xslt - insert div after X li -
i have xslt navigation, want break 2 columns, after every 6 "li" creates new "div"... output this:
<ul> <div class="col"> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> </div> <div class="col"> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a href="#">link</a></li> </div> </ul>
but not quite sure how
my xslt:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" /> <xsl:param name="html-content-type" /> <xsl:template match="/navigationtree"> <xsl:if test="count(//page) > 0"> <ul> <xsl:apply-templates select="page"> <xsl:with-param name="depth" select="1"/> </xsl:apply-templates> </ul> </xsl:if> </xsl:template> <xsl:template match="//page"> <xsl:param name="depth"/> <li> <xsl:attribute name="class"> <xsl:if test="@inpath='true'">inpath </xsl:if> <xsl:if test="position() = 1">firstitem </xsl:if> <xsl:if test="position() = count(//page)">lastitem </xsl:if> <xsl:if test="@active='true'">selected</xsl:if> </xsl:attribute> <a> <xsl:attribute name="class"> <xsl:if test="@inpath='true'">inpath </xsl:if> <xsl:if test="position() = 1">firstitem </xsl:if> <xsl:if test="position() = count(//page)">lastitem </xsl:if> <xsl:if test="@active='true'">current</xsl:if> </xsl:attribute> <xsl:attribute name="href"><xsl:value-of select="@friendlyhref" disable-output-escaping="yes"/></xsl:attribute> <xsl:value-of select="@menutext" disable-output-escaping="yes"/> </a> <div class="icon"> <xsl:text disable-output-escaping="yes"><![cdata[<!--dsfdsfdsf-->]]></xsl:text> </div> <xsl:if test="count(page)"> <ul class="m{@absolutelevel}"> <xsl:apply-templates select="page"> <xsl:with-param name="depth" select="$depth+1"/> </xsl:apply-templates> </ul> </xsl:if> </li> </xsl:template> </xsl:stylesheet>
a way have template matches every 6 page
element:
<xsl:template match="//page[position() mod 6 = 1]"> <div> <xsl:apply-templates select="." mode="secondlevel"/> <xsl:apply-templates select="following-sibling::page[position()<6]" mode="secondlevel"/> </div> </xsl:template>
generating div
, applying second-level template current element , 5 following sibling. second level template 1 have - added mode
:
<xsl:template match="page" mode="secondlevel"> <li> <xsl:attribute name="class"> <xsl:if test="@inpath='true'">inpath </xsl:if> <xsl:if test="position() = 1">firstitem </xsl:if> <xsl:if test="position() = count(//page)">lastitem </xsl:if> <xsl:if test="@active='true'">selected</xsl:if> </xsl:attribute> <a> <xsl:attribute name="class"> <xsl:if test="@inpath='true'">inpath </xsl:if> <xsl:if test="position() = 1">firstitem </xsl:if> <xsl:if test="position() = count(//page)">lastitem </xsl:if> <xsl:if test="@active='true'">current</xsl:if> </xsl:attribute> <xsl:attribute name="href"> <xsl:value-of select="@friendlyhref" disable-output-escaping="yes"/> </xsl:attribute> <xsl:value-of select="@menutext" disable-output-escaping="yes"/> </a> <div class="icon"> <xsl:text disable-output-escaping="yes"><![cdata[<!--dsfdsfdsf-->]]></xsl:text> </div> </li> </xsl:template>
Comments
Post a Comment