[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Extracting Unique element names and attributes fro

Subject: RE: 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
RE:  Extracting Unique element names and attributes fro
> 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))) &gt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.