xsl-list
[Top] [All Lists]

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

2008-10-28 05:51:50

In XSLT 2.0 it's simply

distinct-values(//*/name())
distinct-values(//@*/name())

If you really need to do it with XSLT 1.0, eliminating duplicates is
essentially the same problem as grouping, and you can use the Muenchian
grouping approach.

The preceding-sibling grouping technique isn't going to work (a) because
your nodes are not siblings of each other, and (b) because it only works
where the grouping key is the string-value of the node, not where it is some
other function of the node (here, it's name). Muenchian grouping works for
any string-valued function of a node.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Ganesh Babu N [mailto:nbabuganesh(_at_)gmail(_dot_)com] 
Sent: 28 October 2008 09:38
To: XSL
Subject: [xsl] Extracting Unique element names and attributes 
from a XML file

Hai All,

I need to list out all elements and attribute (unique) in a 
text file for mapping with other XML file.

I am able to get all the elements and attributes but I am 
unable to achieve the uniqueness. Can any body help on this.

I have tested with <xsl:sort> and not(preceding-sibling::* = 
current()). Still I am unable to get the uniqueness.

My XSL is follows:

<?xml version="1.0"?>
<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

      <xsl:output method="text"/>

      <xsl:template match="/">
              <xsl:for-each select="//*">
                      <xsl:value-of select="local-name(.)"/>
                      <xsl:text> </xsl:text>
                      <xsl:choose>
                              <xsl:when test="@*">
                                      <xsl:for-each 
select="@*">@<xsl:value-of select="local-name(.)"/><xsl:text> 
</xsl:text>
                                      </xsl:for-each>
                                      <xsl:text>
                                      </xsl:text>
                              </xsl:when>
                              <xsl:otherwise>
                                      <xsl:text>
                                      </xsl:text>
                              </xsl:otherwise>
                      </xsl:choose>
              </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>

Regards,
Ganesh

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



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