[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Part B - Generic parse.allXML function
At 99/05/11 17:33 -0400, David RR Webber wrote: >OK, continuing this theme, I'm also wanting to explore >if it is possible in XSL to create a "ListNodes" generic tool. Yup. >What I want is to pass any XML, and for the XSL to scan it and >present a complete list of all the TAGS and ATTRIBUTES used >in the well formed XML as a HTML table. The following using XT, based on something James taught us last week, will produce a result with only one stylesheet. Since attribute names and element names could conflict, I go over the data once for elements then once for attributes. Each pass involves a (computationally labourious) repass of the data numerous times. I'll leave it as an exercise to the reader how to throw the HTML table tags around what is below, as the below just reports a textual listing in sorted order of all elements found in the instance followed by all attributes found in the instance. I hope this helps. ............ Ken <?xml version="1.0"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nl "
"> ]> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:template match="/"> <xsl:text>Elements:&nl;</xsl:text> <xsl:for-each select="//*"> <!--first do the elements--> <xsl:sort select="qname(.)"/> <!--in order of their names--> <xsl:choose> <xsl:when test="position()=1"> <!--first in list is unique--> <xsl:value-of select="qname(.)"/> <xsl:text>&nl;</xsl:text> </xsl:when> <xsl:otherwise> <!--find if next is unique--> <xsl:variable name="next" expr="position()+1"/> <xsl:variable name="this" expr="qname(.)"/> <xsl:for-each select="//*"> <!--review list again--> <xsl:sort select="qname(.)"/> <!--same order--> <xsl:if test="position() = $next and not( qname(.) = $this )"> <xsl:value-of select="qname(.)"/> <!--not same as next--> <xsl:text>&nl;</xsl:text> </xsl:if> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:for-each> <xsl:text>&nl;Attributes:&nl;</xsl:text> <xsl:for-each select="//@*"> <!--do the attributes--> <xsl:sort select="qname(.)"/> <!--in order of their names--> <xsl:choose> <xsl:when test="position()=1"> <!--first in list is unique--> <xsl:value-of select="qname(.)"/> <xsl:text>&nl;</xsl:text> </xsl:when> <xsl:otherwise> <!--find if next is unique--> <xsl:variable name="next" expr="position()+1"/> <xsl:variable name="this" expr="qname(.)"/> <xsl:for-each select="//@*"> <!--review list again--> <xsl:sort select="qname(.)"/> <!--same order--> <xsl:if test="position() = $next and not( qname(.) = $this )"> <xsl:value-of select="qname(.)"/> <!--not same as next--> <xsl:text>&nl;</xsl:text> </xsl:if> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet> -- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Website: XSL/XML/DSSSL/SGML services outline, XSL/DSSSL shareware, stylesheet resource library, conference training schedule, commercial stylesheet training materials, on-line XSL CBT. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|