xsl-list
[Top] [All Lists]

Re: [xsl] Encompassing Element extraction

2006-10-16 09:38:29

If you can use xslt2 then it's just

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
<xsl:template match="/*">
  <xsl:for-each-group select=".//*" 
group-by="string-join(ancestor-or-self::*/name(),'/')">
    <xsl:value-of select="'&#10;(',count(current-group()),') 
',current-grouping-key()" separator=""/>
  </xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>

which (if you put <x>...</x> around your posted input to make it well
formed) produces:

$ saxon8 depth.xml depth.xsl
<?xml version="1.0" encoding="UTF-8"?>
(2) x/a1
(2) x/a1/b1
(2) x/a1/b1/c1
(1) x/a1/b1/c2
(1) x/a1/b1/c3
(2) x/a1/b2
(1) x/a1/b2/c2
(1) x/a1/b2/c3
(2) x/a1/b3
(1) x/a1/b3/c1
(1) x/a1/b3/c4


David

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