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

Re: Extracting the grouping from a flat structure

Subject: Re: Extracting the grouping from a flat structure
From: Kevin Jones <kjones@xxxxxxxxxxx>
Date: Tue, 7 Dec 2004 09:42:03 +0000
flat structure
On Monday 06 December 2004 22:52, Peter Wyngaard wrote:
> Hi Kev --
>
> Thanks for your reply.  Could you post sample code for
> your two-pass idea?  I'm really new at XSL and I don't
> think I follow your idea.

Sure, it is rather longer than your original but it might 
help. I have used the non-standard node-set() function in 
here, if you are not familiar with this have a read of 
http://www.xml.com/pub/a/2003/07/16/nodeset.html. I have 
also not tried to reproduce your exact formatting just the 
general structure you needed.

Kev

<xsl:template match='table'>
 <xsl:variable name="postable">
  <index>
   <xsl:for-each select="tr">
    <xsl:if test="th">
     <pos><xsl:value-of select="position()"/></pos>
    </xsl:if>
   </xsl:for-each>
  </index>
 </xsl:variable>

 <xsl:call-template name="genxml">
  <xsl:with-param name="pos"
 	select="node-set($postable)/index/pos"/>
  <xsl:with-param name="nodes" select="tr"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="genxml">
 <xsl:param name="pos"/>
 <xsl:param name="nodes"/>

 <xsl:choose>
  <xsl:when test="count($pos)=0"/>
  <xsl:when test="count($pos)=1">
   <header>
    <xsl:copy-of select="$nodes[position()=number($pos)]"/>
    <xsl:for-each select="$nodes[position()>number($pos)]">
     <row><xsl:copy-of select="."/></row>
    </xsl:for-each>
   </header>
  </xsl:when>
  <xsl:otherwise>
  <header>
   <xsl:copy-of select="$nodes[position()=number($pos)]"/>
   <xsl:for-each select="$nodes[position()>number($pos[1])
           and position()&lt;number($pos[2])]">
    <row>
     <xsl:copy-of select="."/>
    </row>
   </xsl:for-each>
  </header>
  <xsl:call-template name="genxml">
   <xsl:with-param name="pos" select="$pos[position()>1]"/>
   <xsl:with-param name="nodes" select="$nodes"/>
  </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

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.