jmoreno
jmoreno

Reputation: 13561

Close then open tag in loop

Looking at an old xslt (that as far as I know was working, written by someone else ages ago) where a tag is started before a loop and then closed and reopened inside the loop and finally closed after the loop is done. So all tags would end up matching. But when I try to look at it in VS 2013, I get a start tag does not match end tag error.

It's possible this never did work...

Anyway the structure looks like..

<div>
   Blah
   <xsl:for-each>
       different blah
       <xsl:if>
</div>
<div>
       Yet more blah
       </xsl:if>
   </xsl:for-each>
 </div>

Is there a quick way to get this to work, without trying to restructure everything to be in the same loop?

Upvotes: 0

Views: 358

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116982

Is there a quick way to get this to work, without trying to restructure everything to be in the same loop?

It's possible, if you output the intervening tags as text, with disable-output-escaping turned on - for example:

...
<div>
    <!--  something -->
    <xsl:for-each select="item">
        <!--  something -->
        <xsl:if test="@divide='yes'">
            <xsl:text disable-output-escaping="yes">&lt;/div>&#10;&lt;div></xsl:text>
            <!--  something -->
        </xsl:if>
    </xsl:for-each>
</div>
...

This is of course a horrible hack and you should take the first opportunity to replace it with some decent code.

Upvotes: 1

Related Questions