Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select distinct attributes

Status
Not open for further replies.

codeWarrior456

Technical User
Oct 27, 2002
27
0
0
US
I have the following XML sample:

<?xml version="1.0" encoding="utf-8" ?>
<Sample>
<Parent>
<Child>
<Key value="0"/>
</Child>
<Child>
<Key value="1"/>
</Child>
</Parent>
<Parent>
<Child>
<Key value="0"/>
</Child>
<Child>
<Key value="1"/>
</Child>
</Parent>
</Sample>

I want to select all of the distinct value attributes. My final results should be:

0
1

How can I do this?
 
[1] xslt1.0
[1.1] At top level, a xsl:key element
[tt]
<xsl:key name="uniqueattvalue" match="Key/@value" use="." />
[/tt]
[1.2] Then this shows the unique values from a template (no reference to context, or context root / as illustration).
[tt]
<xsl:for-each select="//Key/@value">
<xsl:if test="count(.|key('uniqueattvalue',.)[1])=1">
<xsl:value-of select="." /><xsl:text>[/tt]&#x0a;[tt]</xsl:text>
</xsl:if>
</xsl:for-each>
[/tt]
[2] xslt2.0
[2.1] Again from a template (no reference to context, or context root / as illustration).
[tt]
<xsl:for-each select="distinct-values(//Key/@value)">
<xsl:value-of select="." /><xsl:text>[/tt]&#x0a;[tt]</xsl:text>
</xsl:for-each>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top