xsl-list
[Top] [All Lists]

Re: XPath to get unique nodes based on child node attribute

2005-02-19 14:50:34
Tempore 16:52:30, die 02/19/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit david <david(_at_)wasden(_dot_)com>:

I am trying to get a node set where a child element of each node should have a unique value. I think I can do this with XPath, but can't figure out what how to filter it.
Hi,

The most common way to filter out unique nodes is with keys.
Try something like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>

<xsl:key name="description" match="*[(_at_)QText='Analysis Description:']" use="."/>

<xsl:template match="/">
<xsl:copy-of select="//*[generate-id(key('description',.))=generate-id()]/.."/>
</xsl:template>

</xsl:stylesheet>

outputs:

<SS_Analysis>
<Q_2676_2_Analysis_Descri QText="Analysis Description:">2,3,7,8-TCDD</Q_2676_2_Analysis_Descri>
</SS_Analysis>
<SS_Analysis>
<Q_2676_2_Analysis_Descri QText="Analysis Description:">601/602 Volatiles</Q_2676_2_Analysis_Descri>
</SS_Analysis>
<GW_Analysis>
<Q_3692_2_Analysis_Descri QText="Analysis Description:">2(2-Butoxyethoxy)ethanol</Q_3692_2_Analysis_Descri>
</GW_Analysis>
<DW_Analysis>
<Q_5066_2_Analysis_Descri QText="Analysis Description:">507 Pesticides</Q_5066_2_Analysis_Descri>
</DW_Analysis>


regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Ceterum censeo XML omnibus esse utendum

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>