www.webdeveloper.com
Results 1 to 2 of 2

Thread: XSLT/XPath: How to display single node occurence

  1. #1
    Join Date
    May 2003
    Posts
    599

    Question XSLT/XPath: How to display single node occurence

    Hello,

    I'm working on a for-each element that will display only one occurrence of a name node, even if there are several occurences of that name in the XML doc. Here's an example of what I need:

    XML doc:
    <root>
    <name>Janice Smith</name>
    <name>Janice Smith</name>
    <name>Michael Jones</name>
    <name>Michael Jones</name>
    <name>Michael Jones</name>
    </root>

    XSLT FOR-EACH ELEMENT:
    <xsl:for-each select="root/name"><!-- <<<<---something is missing here -->
    <xsl:value-of select="." /><br />
    </xsl:for-each>

    WANTED RESULT:
    Janice Smith
    Michael Jones

    I'll continue to work on a possible solution until/if I hear get from someone else. Thanks for any help.
    KWilliams
    -----------------------
    It's the end of the world as we know it...and I feel fine

  2. #2
    Join Date
    May 2003
    Posts
    599

    resolved

    I was able to come up with a solution that works in 1.0, and here it is:

    <xsl:for-each select="root/name[not(text() = ../preceding-sibling::name/text())]">

    Another user noted that if I was using 2.0, I could use the distinct-values function. Just another reason why I need to upgrade soon. Anyway, thanks.
    KWilliams
    -----------------------
    It's the end of the world as we know it...and I feel fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles