xsl-list
[Top] [All Lists]

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

2010-09-23 20:39:35
AH!!

I see! I thought of that kind of, but was thinking there was some hairy xpath i 
could put together to get all of the elements before the S5.

Thanks again!!

(Other than your books, do you have any video tutorials/training?) :)

Thanks,


Russ


On Thu, Sep 23, 2010 at 11:57:12PM +0100, Michael Kay wrote:

<xsl:for-each-group group-starting-with="S5">
<xsl:choose>
<xsl:when test="current-group()[1] is an element that does not match S5">
<xsl:copy-of select="current-group()"/>
</
<xsl:otherwise>
<section level="5">
         recurse, select="current-group()[position() gt 1]"

I hope this gives the idea.

Michael Kay
Saxonica


On 23/09/2010 10:53 PM, russurquhart1(_at_)verizon(_dot_)net wrote:
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>
--~--




--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--