Breaking xslt paradigm

Hey guys,

writing xslt is some kind of special, isn’t it? As a original developer who started with php need to pay special attention to the xslt paradigm.

In my case I have a dropdown navigation with two columns after each 4 items where you need to split the current div tag into a new.

You can’t do something like this:

<xsl:if test=”position () = 4″>
</div><div class=”Submenu”>
</xsl:if>

Right?

The solution is some kind of “hack”, so only use this if you have tried to think over your code and another solution.

<xsl:variable name=”divider”>
  <![CDATA[</div><div class="Column">]]>
</xsl:variable>

Now you can do:

<xsl:if test=”(position() mod 4) = 0″>
  <xsl:value-of select=”$divider” disable-output-escaping=”yes”/>
</xsl:if>

Enjoy ;)

One Response to “Breaking xslt paradigm”

  1. Bryan says:

    You should not have to use a hack like this, it appears you have misunderstood the xslt paradigm. You are using a procedural approach (a common mistake). If you give more detail about what you are trying to acheive I am certain there is a better solution.

Leave a Reply