Re: [xsl] From filepaths to XML hierarchy

Subject: Re: [xsl] From filepaths to XML hierarchy
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 27 Dec 2011 14:50:22 +0100
Jesper Tverskov wrote:

Let us reduce the problem to the following input file:
<x>
    <a><b><c/></b></a>
    <a><b><d/></b></a>
    <a><b><e/></b></a>
    <h><i/></h>
    <h><j/></h>
</x>

How can I transform it into the following output:
<x>
    <a><b><c/><d/><e/></b></a>
    <h><i/><j/></h>
</x>

Try


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

  <xsl:template match="*">
    <xsl:param name="group" select="*"/>
    <xsl:copy>
      <xsl:for-each-group select="$group" group-by="node-name(.)">
        <xsl:apply-templates select=".">
          <xsl:with-param name="group" select="current-group()/*"/>
        </xsl:apply-templates>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

although I am not sure I have understood completely what you want to achieve.


--


	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

Current Thread