[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:for-each-group and identity transform
To make me more clear. I have made an "unflatten.xsl" using Michael Kay's code in 4th edition of "XSLT 2.0 and XPath 2.0", page 340, as point of departure. I have modified it to get real XHTML input working. I think my stylesheet works, but I run into the good old problem of attributes being copied out of the DTD. So I was looking for a way to get additional templates in place to delete those attributes again as I use to do when making an identity transform. But I have only managed to do so in a second transformation. So here is my question: Is it possible to get both the xsl:for-each-group and a modified identity transform working in one transformation? <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns="http://www.w3.org/1999/xhtml" xpath-default-namespace="http://www.w3.org/1999/xhtml"> <xsl:output method="xml" indent="yes"/> <xsl:template match="html"> <xsl:copy> <xsl:attribute name="xml:lang">en</xsl:attribute> <xsl:apply-templates select="head|body"/> </xsl:copy> </xsl:template> <xsl:template match="head"> <xsl:copy-of select="."/> </xsl:template> <xsl:template match="body"> <xsl:copy> <xsl:for-each-group select="element()|comment()|processing-instruction()" group-starting-with="h1"> <xsl:apply-templates select="." mode="group"/> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="h1" mode="group"> <h> <xsl:copy-of select="descendant::node()"/> </h> <xsl:for-each-group select="current-group() except ." group-starting-with="h2"> <xsl:apply-templates select="." mode="group"/> </xsl:for-each-group> </xsl:template> <xsl:template match="h2|h3|h4|h5|h6" mode="group"> <xsl:variable name="this" select="name()"/> <xsl:variable name="next" select="translate($this, '23456', '34567')"/> <section> <h> <xsl:copy-of select="descendant::node()"/> </h> <xsl:for-each-group select="current-group() except ." group-starting-with="*[name() = $next]"> <xsl:apply-templates select="." mode="group"/> </xsl:for-each-group> </section> </xsl:template> <xsl:template match="element()|comment()|processing-instruction()" mode="group"> <xsl:copy-of select="current-group()"/> </xsl:template> </xsl:stylesheet> Cheers, Jesper
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|