Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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