[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: few nodes are missing ??

Subject: RE: few nodes are missing ??
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Fri, 5 Sep 2003 01:13:05 +0100
xsl select generate id
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.