Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Barry 99 posts 187 karma points
    Oct 08, 2009 @ 19:47
    Barry
    0

    XSLT conditions and DIVs

    If I have an IF condition, I dont seem to be able to conditionally create a DIV eg..

    <xsl:if test="position() mod 2 =1">

    <div class="row">

    <div class="first">

    </xsl:if>

    <xsl:if test="position() mod 2 != 1">

        <div>

    </xsl:if>

     

    It complains that there is no matching DIV. This is because I need to create a ROW div every odd record (1, 3 etc). I will close the DIV every even record or if the current record is the same as the count (e.g. the last).

  • Barry 99 posts 187 karma points
    Oct 08, 2009 @ 19:58
    Barry
    0

    Got it. .. 

     

    this is my end row code

    <xsl:if test="position() mod 2 = 1 ">

        <xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text>

    </xsl:if>  

        <xsl:if test="position() mod 2 != 1 or (position() mod 2 = 1 and position() = count()) ">

        <xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text>

        <xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text>

    </xsl:if>

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 08, 2009 @ 22:30
    Nik Wahlberg
    2

    You could also approach this using templates. Take a look at:

    <xsl:call-template name=""></xsl:call-template>

    This way you can call different tempaltes base on the results of your mod. Makes for a cleaner and more readable XSLT.

    HTH

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies