Subject: Re: [xsl] grouping xhtml title with first sibling From: Matthieu Ricaud-Dussarget <matthieu.ricaud@xxxxxxxxx> Date: Tue, 18 Jan 2011 14:46:16 +0100 |
<!--default copy--> <xsl:template match="* | @* | processing-instruction() | comment()"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template>
<!--keep namespace on top element--> <xsl:template match="html"> <html xmlns="http://www.w3.org/1999/xhtml"> <xsl:apply-templates/> </html> </xsl:template>
<xsl:template match="body"> <xsl:copy copy-namespaces="no"> <xsl:copy-of select="@*"/> <xsl:call-template name="group"> <xsl:with-param name="level" select="1"/> <xsl:with-param name="nodes" select="*"/> </xsl:call-template> </xsl:copy> </xsl:template>
You don't need dynamic XPath evaluation for this.
The basic structure you want can be achieved with
<xsl:template name="group">
<xsl:param name="nodes" as="node()"/>
<xsl:param name="level" as="xs:integer"/>
<xsl:for-each-group select="*" group-starting-with="*[local-name() = concat('h', $level)]">
<div>
<xsl:call-template name="group">
<xsl:with-param name="nodes" select="current-group()"/>
<xsl:with-param name="level" select="$level + 1"/>
</xsl:call-template>
</div>
</xsl:for-each-group>
</xsl:template>
and then start the recursion off with level="1". You'll have to modify this slightly to avoid getting a div element for the elements that precede the first hN element at each level.
Michael Kay
Saxonica
-- Matthieu Ricaud IGS-CP Service Livre numirique
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] grouping xhtml title with, Michael Kay | Thread | Re: [xsl] grouping xhtml title with, Michael Kay |
Re: [xsl] grouping xhtml title with, Michael Kay | Date | Re: [xsl] grouping xhtml title with, Michael Kay |
Month |