RE: [xsl] Extracting Unique element names and attributes from a XML file [SEC=UNCLASSIFIED]

Subject: RE: [xsl] Extracting Unique element names and attributes from a XML file [SEC=UNCLASSIFIED]
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 29 Oct 2008 10:45:29 -0400
At 06:56 PM 10/28/2008, Mike wrote:
saxon:evaluate seems quite unnecessary here (and will be a lot more
expensive than necessary)....

Also, Mike earlier suggested using xsl:for-each-group, which offers a nice solution:


<xsl:for-each-group select="//*" group-by="name()">
  <xsl:text>&#xA;&#xA;</xsl:text><!-- two new lines -->
  <xsl:value-of select="current-grouping-key()"/>
  <xsl:for-each-group select="current-group()/@*" group-by="name()">
    <xsl:text>&#xA;  </xsl:text><!-- new line, indent -->
    <xsl:value-of select="current-grouping-key()"/>
  </xsl:for-each-group>
</xsl:for-each-group>

This is somewhat different from what was posted, in that it lists distinct attributes that may appear with each element, but this is usually useful information -- and if you do want a list of attributes appearing absolutely, just do the element thing again, except selecting "//@*". (Also, I haven't taken the trouble to make HTML out of it.)

This approach can be taken one more step to report values of attributes, or repeating values of attributes (which sometimes makes for less noise).

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread