[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transform inline-block type elements to block-leve
> How will this work with my example given? Not very well.... You'd be better with something like the following. (Excepting of course some people reading the currently active parallel thread on this mailing list may wish to comment adversely on my choice of variable and mode names..) <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output indent="no"/> <xsl:template match="/"> <xsl:variable name="a"> <xsl:apply-templates mode="a"/> </xsl:variable> <xsl:apply-templates mode="b" select="$a"/> </xsl:template> <xsl:template mode="a" match="root|p|ul|li"> <xsl:copy> <xsl:apply-templates mode="a"/> </xsl:copy> </xsl:template> <xsl:template mode="a" match="em|strong|code"> <xsl:param name="inlines" tunnel="yes"/> <xsl:apply-templates mode="a" > <xsl:with-param name="inlines" tunnel="yes" select="$inlines,name()"/> </xsl:apply-templates> </xsl:template> <xsl:template mode="a" match="text()"> <xsl:param name="inlines" tunnel="yes"/> <text inlines="{$inlines}"> <xsl:value-of select="normalize-space(.)"/> </text> </xsl:template> <xsl:template mode="b" match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="b"/> </xsl:copy> </xsl:template> <xsl:template mode="b" match="p"> <xsl:text> </xsl:text> <xsl:for-each-group select="*" group-adjacent="boolean(self::ul)"> <xsl:choose> <xsl:when test="current-grouping-key()"> <xsl:apply-templates mode="b" select="current-group()"/> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> <p> <xsl:apply-templates mode="b" select="current-group()"/> </p> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> <xsl:text> </xsl:text> </xsl:template> <xsl:template mode="b" match="li"> <xsl:text> </xsl:text> <li> <xsl:for-each-group select="*" group-adjacent="boolean(self::ul)"> <xsl:choose> <xsl:when test="current-grouping-key()"> <xsl:apply-templates mode="b" select="current-group()"/> </xsl:when> <xsl:otherwise> <xsl:text> </xsl:text> <p> <xsl:apply-templates mode="b" select="current-group()"/> </p> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </li> <xsl:text> </xsl:text> </xsl:template> <xsl:template mode="b" match="text"> <xsl:param name="s" select="tokenize(@inlines,'\s+')[.!='']"/> <xsl:choose> <xsl:when test="empty($s)"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:element name="{$s[1]}"> <xsl:apply-templates mode="b" select="."> <xsl:with-param name="s" select="$s[position()!=1]"/> </xsl:apply-templates> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> $ saxon8 inline.xml inline.xsl <?xml version="1.0" encoding="UTF-8"?><root> <p>one<em>two</em></p> <ul> <li> <p><em>three</em></p> </li> <li> <p><em><strong>four</strong></em></p> <ul> <li> <p><em><strong><code>five</code></strong></em></p> </li> </ul> <p><em><strong><code>six</code></strong></em></p> </li> </ul> </root>
|
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
|