xsl-list
[Top] [All Lists]

Re: Listing all element/attributes/attribute values

2005-07-07 06:31:16
Hi,

Tempore 14:58:36, die 07/07/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit James Cummings <cummings(_dot_)james(_at_)gmail(_dot_)com>:

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)

--~------------------------------------------------------------------
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>