Eliminating duplicate entries

Discussion in 'XML' started by A.T., Jul 22, 2004.

  1. A.T.

    A.T. Guest

    I have an XML document that looks like the following, except that it
    has about 30,000 entries.
    <root>
    <version id="A-0000">
    <!many elements within- removed for ease of reading>
    </version>
    <version id="A-0000">
    </version>
    <version id="A-0001">
    </version>
    </root>


    I want to create a stylesheet where a flag goes up when there are
    duplicates like:
    <version id="A-0256">
    </version>
    <version id="A-0256">
    </version>

    I'm trying to use

    <xsl:template match="version">
    <xsl:choose>
    <xsl:when test="preceding::node()=node()">
    <td bgcolor="blue"><xsl:value-of select="id"/></td>
    </xsl:when>
    <xsl:eek:therwise>
    <td><xsl:value-of select="id"/></td>
    </xsl:eek:therwise>
    </xsl:choose>
    <xsl:apply-templates select="version"/>
    </xsl:template>

    but I can't seem to get the test="" part of it to work. Please help.
    A.T., Jul 22, 2004
    #1
    1. Advertising

  2. <xsl:template match="version">
    <xsl:choose>
    <xsl:when test="preceding::node()=node()">

    your currnt node is version so the above test is testing if _any_
    preceding node anywhere in the document (of any type, element, text,
    comments, ..) is equal to any child node of the current node.

    The current node apparently only has one child a text node consisting of
    a newline character so you are asking if any previous node has string
    value being a newline.

    You want to know if the previous sibling element is equal to the current
    node
    so that's
    <xsl:template match="version">
    <xsl:choose>
    <xsl:when test="preceding-sibling::*=.">

    or
    <xsl:template match="version">
    <xsl:choose>
    <xsl:when test="preceding-sibling::*[1]=.">

    if your input is already sorted and you only need check teh immediately
    preceding element.


    David
    David Carlisle, Jul 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wade
    Replies:
    3
    Views:
    1,678
  2. Matt B
    Replies:
    6
    Views:
    463
    Matt B
    Oct 8, 2005
  3. sean
    Replies:
    5
    Views:
    286
    Peter Otten
    Nov 26, 2003
  4. Paul
    Replies:
    9
    Views:
    457
    Paul Rubin
    Jul 7, 2004
  5. Don Bruder
    Replies:
    3
    Views:
    952
    spikeysnack
    Aug 3, 2010
Loading...

Share This Page