[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: Mon, 13 Dec 2004 11:42:43 +0000
xsl pos
Hi Peter,

Give the version below a try. It's really the same algorithm 
but I have replaced the nodeset chopping by some guided 
searching of the document. This appears to be much easier 
for Xalan to handle.

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:variable name="headers" select="tr[th]"/>
  <xsl:for-each select="$headers[1]">
   <xsl:call-template name="walk">
    <xsl:with-param name="headers" 
select="$headers[position()>1]"/>
    <xsl:with-param name="pos" 
select="xalan:nodeset($postable)/index/pos"/>
   </xsl:call-template>
  </xsl:for-each>
 </xsl:template>
 
 <xsl:template name="walk">
  <xsl:param name="headers"/>
  <xsl:param name="pos"/>
  <xsl:choose>
   <xsl:when test="count($pos)=0"/>
   <xsl:when test="count($pos)=1">
    <header>
     <xsl:copy-of select="."/>
     <xsl:for-each 
select="following-sibling::*[position()>1]">
      <row>
       <xsl:copy-of select="."/>
      </row>
     </xsl:for-each>
    </header>
   </xsl:when>
   <xsl:otherwise>
    <header>
     <xsl:copy-of select="."/>
     <xsl:variable name="rows" select="$pos[2]-$pos[1]"/>
     <xsl:for-each 
select="following-sibling::*[1]/following-sibling::*[position()&lt;
$rows]">
      <row>
       <xsl:copy-of select="."/>
      </row>
     </xsl:for-each>
    </header>
    <xsl:for-each select="$headers[1]">
     <xsl:call-template name="walk">
      <xsl:with-param name="headers" 
select="$headers[position()>1]"/>
      <xsl:with-param name="pos" 
select="$pos[position()>1]"/>
     </xsl:call-template>
    </xsl:for-each>
   </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.