|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Listing all element/attributes/attribute values
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)"/>) <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> </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> </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...
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








