xsl-list
[Top] [All Lists]

RE: XML Group with XSL

2004-04-22 10:27:04
-----Original Message-----
From: aalikaj(_at_)ntuitive(_dot_)com [mailto:aalikaj(_at_)ntuitive(_dot_)com]


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="*[(_at_)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



<Prev in Thread] Current Thread [Next in Thread>