View Single Post
  #1 (permalink)  
Old April 4th, 2007, 01:35 PM
QuickSilver002 QuickSilver002 is offline
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing duplicate nodes post-process

(newbie question)
I'm trying to do some post-processing on the results of an XSLT that was made by someone else. My goal is to trim off some duplicate nodes from the results of their transformation. I want my final transform to be a one-step process, so I capture the results of the previous transform in a variable and then I want to modify the nodes in that variable (node-set?).

<xsl:variable name="ORIGINAL_RESULTS">

</xsl:variable>

So, after the above is run, the value of $ORIGINAL_RESULTS is the following:
<XML>
  <A>
    <B>
      <uniqueName>UN1</uniqueName>
    </B>
    <B>
      <uniqueName>UN2</uniqueName>
    </B>
    <B>
      <uniqueName>UN1</uniqueName>
    </B>
  </A>
</XML>

The modification I want to perform is to trim out all the nodes that have duplicate values for their uniqueName children. (i.e. The third <B> node above will be trimmed out) I think the test I want to run is the following:

<xsl:if test="uniqueName">
  <xsl:choose>
    <xsl:when test="uniqueName/text() != preceding-sibling::uniqueName/text()">
      <-- good, output -->
    </xsl:when>
    <xsl:otherwise>
      <-- bad, don't output>
    </xsl:otherwise>
  </xsl:choose>
</xsl:if>

If the node tested has a child named "uniqueName" and the value of that child already exists previously, don't output it.

My problem is that I don't know how to take the variable ORIGINAL_RESULTS and apply the "filter" I've made and have it output the entire XML results except what I've filtered out. Any ideas? (This is probably very simple, I'm new to XSLT though)w how to take the variable ORIGINAL_RESULTS and apply the "filter" I've made and have it output the entire XML results except what I've filtered out. Any ideas? (This is probably very simple, I'm new to XSLT though)

Reply With Quote