Re: [xsl] Listing all element/attributes/attribute values

Subject: Re: [xsl] Listing all element/attributes/attribute values
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 07 Jul 2005 15:31:16 +0200
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