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

Re: Listing all element/attributes/attribute values

Subject: Re: Listing all element/attributes/attribute values
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 07 Jul 2005 15:31:16 +0200
xslt2 generate id
Hi,

Tempore 14:58:36, die 07/07/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit James Cummings <cummings.james@xxxxxxxxx>:

What I want to do is with any well-formed XML document list all the
elements, attributes and attribute-values in a sorted list.

This requires some grouping technique. I used muenchian:


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

<xsl:output method="text"/>

<xsl:key name="element" match="*" use="name()"/>
<xsl:key name="attribute" match="@*" use="concat(name(..),name())"/>
<xsl:key name="attributevalue" match="@*" use="concat(name(..),name(),.)"/>

<xsl:template match="/">
<xsl:for-each select="//*[generate-id()=generate-id(key('element',name()))]">
<xsl:sort select="name()"/>
<xsl:variable name="elements" select="key('element',name())"/>
<xsl:value-of select="name()"/> (<xsl:value-of select="count($elements)"/>)&#10;<xsl:text/>
<xsl:for-each select="$elements/@*[generate-id()=generate-id(key('attribute',concat(name(..),name())))]">
<xsl:sort select="name()"/>
<xsl:variable name="attributes" select="key('attribute',concat(name(..),name()))"/>
<xsl:text> - </xsl:text><xsl:value-of select="name()"/><xsl:text>&#10;</xsl:text>
<xsl:for-each select="$attributes[generate-id()=generate-id(key('attributevalue',concat(name(..),name(),.)))]">
<xsl:sort select="."/>
<xsl:text> = </xsl:text><xsl:value-of select="."/><xsl:text>&#10;</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>

I hope you're mail client does not wrap this message. It'll look like un-legible character soup:(


Is this even easier in xslt2?
Grouping is made easier in xslt2, I doubt not you will soon get another reply with an xslt2 solution...


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Spread the wiki (http://www.wikipedia.org)

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.