Jump to content

Xslt/xpath: How To Display Single Node Occurence


kwilliams

Recommended Posts

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 SmithMichael JonesI'll continue to work on a possible solution until/if I hear get from someone else. Thanks for any help.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...