2

I need to render a wrapper to items. I have a list of items that i want to display them in a DVWP, and every 3 items will be in a wrapper, for example:

<div>
  <div>item</div>
  <div>item</div>
  <div>item</div>
</div>
<div>
  <div>item</div>
  <div>item</div>
  <div>item</div>
</div>

you got the point...

I used this one:

<xsl:if test="position() = first()">
  <xsl:text disable-output-escaping="yes">&amp;lt;div&amp;gt;</text>
</xsl:if>

<xsl:if test="position() mod 3 = 1">
  <xsl:text disable-output-escaping="yes">&amp;lt;/div&amp;gt;</text>
  <xsl:text disable-output-escaping="yes">&amp;lt;div&amp;gt;</text>
</xsl:if>

<xsl:if test="position() = last()">
  <xsl:text disable-output-escaping="yes">&amp;lt;/div&amp;gt;</text>
</xsl:if>

(of course in the right order in the HTML rowview)

Is there another way, more complex-safe way of doing it?

Thanks a lot.

2 Answers 2

1

You could use the ddwrt setvar and getvar but I'm not sure if that will give you any more in this case than using position(). I think what you have is fine.

0

The change I would suggest is that you don't need the first and last tests. Assuming that you are using the standard dvt_1, dvt_1.body and dvt_1.rowview templates, emit the opening and closing divs in the dvt_1 template. If you have a different template structure, just emit them in the template that calls the one which emits the items. That will save the expense of doing the first abd last tests for each item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.