-1

I'm having trouble trying to extract a unique list of jobs from two combined lists. The two lists are in the same document but have different structures.

My plan was to build a node set combining the two lists. I would then have a single list with all elements having the same structure. Then I could select unique members to a second node set.

I used the Muenchian method of extracting unique members as described here.

Any suggestions why this is not working?

  <!--create a key to use Muenchian grouping on jobs-->
  <xsl:key name="keyJobID" match="Job" use="JobID"/>

  <!--select unique job nodes from a node-set-->
  <xsl:template name="UniqueJobNodes">
    <xsl:param name="List"/>
    <xsl:for-each select="$List/Job[not(generate-id() = generate-id(key('keyJobID', JobID)[1]))]">
      <xsl:text>does-this-work?</xsl:text>
    </xsl:for-each>
  </xsl:template>

The node set I'm passing to the template seems correct. When I use '$List/Job' without the conditional I get results.

The input node-set looks like this:

  <Job Primary="1">
    <JobProficiency>100</JobProficiency>
    <JobID>300.Supervisor</JobID>
    <JobPayRate>15.4</JobPayRate>
  </Job>
  <Job>
    <JobProficiency>50</JobProficiency>
    <JobID>SUPERVISOR</JobID>
    <JobPayRate>15.4</JobPayRate>
  </Job>
Community
  • 1
  • 1
Jay
  • 13,803
  • 4
  • 42
  • 69
  • 3
    Consider to post minimal but complete samples to allow us to easily reproduce the problem. We need to see the input and the call of the template. – Martin Honnen Aug 17 '15 at 19:24

1 Answers1

-1

I found a working solution. I believe the issue is that the key() function operates against the current document node and not the node-set in the variable. Since I could sort the list without issue I used this instead of an xsl key

  <xsl:template name="UniqueJobNodes">
    <xsl:param name="List"/>
    <xsl:for-each select="$List/Job">
      <xsl:sort select="JobID/text()" />
      <xsl:if test="not(following-sibling::Job[JobID/text() = self::JobID/text()])" >
        <xsl:copy-of select="."/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
Jay
  • 13,803
  • 4
  • 42
  • 69