Subject: RE: [xsl] Extracting Unique element names and attributes from a XML file [SEC=UNCLASSIFIED] From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 28 Oct 2008 22:56:11 -0000 |
> with XSLT 2.0 using distinct-values and Saxon extensions > (saxon:evaluate) me and my colleague Nick Ardlie, just > created this code below yesterday to list all unique elements > and attributes for each element: saxon:evaluate seems quite unnecessary here (and will be a lot more expensive than necessary) > <xsl:template name="LIST_ATTRIBUTES"> > <xsl:param name="ELEMENT"/> > <xsl:variable name="XPATH_EXPR" > select="concat('$p1//*[name()=''',$ELEMENT,''']/@*/name()')"/> > <xsl:if > test="count(distinct-values(saxon:evaluate($XPATH_EXPR, > $ROOT))) > 0"> Just do <xsl:if test="exists($ROOT//*[name()=$ELEMENT]/@*)"> Note: count(X)>0 is equivalent to exists(X), and exists(distinct-values(X)) is equivalent to exists(X). > <xsl:for-each > select="distinct-values(saxon:evaluate($XPATH_EXPR, $ROOT))"> Here you can do select="distinct-values($ROOT//*[name()=$ELEMENT]/@*/name())" Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Extracting Unique element, Enrico . Raymund | Thread | RE: [xsl] Extracting Unique element, Wendell Piez |
Re: [xsl] Extracting Unique element, Enrico . Raymund | Date | Re: [xsl] Displaying Unique attribu, Ganesh Babu N |
Month |