RE: [xsl] XML Group with XSL

Subject: RE: [xsl] XML Group with XSL
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Thu, 22 Apr 2004 19:27:04 +0200
> -----Original Message-----
> From: aalikaj@xxxxxxxxxxxx [mailto:aalikaj@xxxxxxxxxxxx]
> 

> I'm still trying to solve my problem.
> 
> In a few words, i'm trying to explain my problem again.
> 
> I have an XML file with this format:
> 

Hi,

That sample looks a lot easier to handle than the one you posted yesterday.

Try this:

<xsl:stylesheet ...>

<xsl:key name="n-id-key" match="*[@ID]"
         use="concat(count(ancestor::*),' ',name(),' ',@ID)" />

<xsl:template match="/">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="ROOT">
  <xsl:copy>
    <xsl:apply-templates select="*[generate-id()=generate-id(
                           key('n-id-key',concat(
                             '1 ', name(),' ',@ID)))]" />
  </xsl:copy>
</xsl:template>

<xsl:template match="*">
  <xsl:variable name="vcount" select="count(ancestor::*)+1" />
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:copy-of select="normalize-space(text())" />
    <xsl:apply-templates select="../*[name()=name(current()) and
                           @ID=current()/@ID]/*[
                           generate-id()=generate-id(
                             key('n-id-key',concat(
                               $vcount,' ',name(),' ',@ID)))]" />
  </xsl:copy>
</xsl:template>

Seems to be leading to the wanted result...

Hope this helps!


Cheers,

Andreas

Current Thread