RE: [xsl] few nodes are missing ??

Subject: RE: [xsl] few nodes are missing ??
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Fri, 5 Sep 2003 01:13:05 +0100
Hi

This stylesheet, when applyied to your xml gives the result you want:
  <!-- sets the separator char, can change to whatever you want -->
  <xsl:variable name="sep" select="&quot;&apos;&quot;"/>
  <xsl:key match="@ColName" name="col" use="."/>
  <!-- get unique global @ColName's -->
  <xsl:variable name="cols"
select="//@*[generate-id()=generate-id(key('col',.))]"/>

  <xsl:template match="Root">
    <!-- Set the header -->
    <xsl:value-of select="concat(name(),'ID')"/>
    <xsl:apply-templates mode="headers" select="Node1[1] | @*"/>
    <xsl:text>&#10;</xsl:text>
    <!-- Start processing -->
    <xsl:value-of select="generate-id()"/>
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates select="Node1"/>
  </xsl:template>

  <!-- Headers -->
  <xsl:template match="@*" mode="headers">
    <xsl:value-of select="concat($sep,name())"/>
  </xsl:template>
  <xsl:template match="*" mode="headers">
    <xsl:value-of select="concat($sep,name(),'ID')"/>
    <xsl:apply-templates mode="headers" select="@*"/>
    <xsl:value-of select="concat($sep,name(),'ID')"/>
    <xsl:apply-templates mode="headers" select="*"/>
  </xsl:template>
  <xsl:template match="CLASS" mode="headers">
    <xsl:value-of select="concat($sep,@Table,'ID')"/>
    <xsl:apply-templates mode="headers" select="$cols"/>
  </xsl:template>
  <xsl:template match="@ColName" mode="headers">
    <xsl:value-of select="concat($sep,.)"/>
  </xsl:template>

  <!-- Elements -->
  <xsl:template match="@*">
    <xsl:value-of select="concat($sep,.)"/>
  </xsl:template>
  <xsl:template match="Node1">
    <xsl:if test="position()&gt;1">
      <!-- if this is not the first Node1 then must fill with sep -->
      <xsl:for-each select="../@*">
        <xsl:value-of select="$sep"/>
      </xsl:for-each>
    </xsl:if>
    <xsl:value-of select="concat($sep,generate-id(..),$sep,generate-id())"/>
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates select="*"/>
  </xsl:template>
  <xsl:template match="CLASS">
    <xsl:value-of select="concat($sep,generate-id(..),$sep,generate-id())"/>
    <xsl:apply-templates select="Row"/>
  </xsl:template>
  <xsl:template match="Row">
    <xsl:variable name="cur" select="Column"/>
    <xsl:if test="position()&gt;1">
      <!-- if not the first Row then fill with sep according to ancestor and
their attributes -->
      <xsl:for-each select="ancestor::*">
        <xsl:value-of select="$sep"/>
        <xsl:for-each select="@*">
          <xsl:value-of select="$sep"/>
        </xsl:for-each>
      </xsl:for-each>
    </xsl:if>
    <!-- here is where the work is done. For each unique copy the current
Column whose @ColName equals to unique(@ColName) -->
    <xsl:for-each select="$cols">
      <xsl:value-of select="concat($sep,$cur[@ColName=current()])"/>
    </xsl:for-each>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

Hope this helps

Regards,
Americo Albuquerque


(...)


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread