xsl-list
[Top] [All Lists]

Re: [xsl] Making nested elements from elements with level attributes

2010-09-23 16:53:55
Thank you!  I have modified your suggestions to sort of work. The code is below.

I need to carry to the result tree, the siblings that fall in the current 
section. I know i need something along the lines of  following-sibling: up to 
next section. Or is there another way to get those in this algorithm.

The current line only get all siblings but the headings.

Any suggestions?

Thank you so much!

Russ

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version='2.0' xmlns:xs="http://www.w3.org/2001/XMLSchema";>
<xsl:template name="process-level">
  <xsl:param name="population" required="yes" as="element()*"/>
  <xsl:param name="level" required="yes" as="xs:integer"/>
  <xsl:for-each-group select="$population" 
       group-starting-with="section[xs:integer(@level) eq $level]">
    <xsl:element name="Subsection">
      <xsl:value-of select="@level"/> 

<!--  I know this line needs to be changed to get the siblings up to the next 
section element. -->

      <xsl:copy-of select="following-sibling::*[name()!='section']"/>

      <xsl:call-template name="process-level">
        <xsl:with-param name="population" 
                        select="current-group()[position() != 1]"/>
        <xsl:with-param name="level" 
                        select="$level + 1"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:for-each-group>
</xsl:template>
<xsl:template match="article">
  <xsl:call-template name="process-level">
  <xsl:with-param name="population" select="./section"/>
  <xsl:with-param name="level" select="2"/>
  </xsl:call-template>
</xsl:template>
</xsl:stylesheet>


The elegant algorithm IS a recursive routine with a named template: see

http://www.saxonica.com/papers/ideadb-1.1/mhk-paper.xml

for a solution of a similar problem (Stage Two is the relevant part)

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--