Copied to clipboard

Flag this post as spam?

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

  • rajeev 18 posts 38 karma points
    Feb 09, 2011 @ 02:02

    creating unclosed tag in xslt

    I have two nested foreach loop. inner loop generates <td> tags to construct a table. IF i try to add this line

    <xsl:if test="position() mod 3 =0"><tr></xsl:if>  

    Similary another if for </tr> tag.  

    But when I saves my xslt it gives me error for unclosed <tr> tag.

    Please help me how  I can do this.


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 09, 2011 @ 06:25
    Jan Skovgaard

    Hi rajeev

    You need to cheat a bit here in order to make this work

    Try writing this

    <xsl:if test="position() mod 3 =0"><xsl:text disable-output-escaping="yes"><![CDATA[<tr>]]></xsl:text></xsl:if> - This should be enough and let's the XML parser know it should not try to parse this element.

    So to make your </tr> work I guess it should be placed within the same test? Like this

    <xsl:if test="position() mod 3 =0">

    <xsl:text disable-output-escaping="yes"><![CDATA[<tr>]]></xsl:text>

    <!--your code here-->

    <xsl:text disable-output-escaping="yes"><![CDATA[</tr>]]></xsl:text>


    Does this help?


  • rajeev 18 posts 38 karma points
    Feb 09, 2011 @ 06:38

    Even if i do this  <table><xsl:text disable-output-escaping="yes"><![CDATA[<tr>]]></xsl:text><xsl:text disable-output-escaping="yes"><![CDATA[</tr>]]></xsl:text></table>

    I get nothing. I can't see the <tr> tag in source of page that i need to show.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Feb 09, 2011 @ 20:52
    Chriztian Steinmeier

    Hi rajeev,

    Take a look at my solution for this one:

    which was a modification of this one:

    They show how to properly deal with tables (or other grouped output).

    Please ask away here if you need further help - maybe show a little more of your code, so we can guide you as good as possible.


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 09, 2011 @ 21:01
    Jan Skovgaard

    Hi Rajeev

    You should definently listen to Chriztian on this one and not my evil twin who must have posted earlier *ahem*...:-) That's apparently a study on how NOT to do it. I hang my head in shame and go to the naughty corner for a while.

    Thumbs up Chriztian and thanks for making elegant solutions :-)


Please Sign in or register to post replies

Write your reply to: