2

I am needing some assistance in creating a stylesheet that can output a single row item into two separate DIVs.

Essentially, I am trying to turn list items into tabs using jQuery's UI library. The finalized output would need to look something like this:

 <div id="tabs">
 <li><a href="#tabs-{@ID}"><xsl:value-of select=@Title />Title of List Item 1</a></li>
 <li><a href="#tabs-{@ID}"><xsl:value-of select=@Title />Title of List Item 2</a></li>
 </div>

 <div id="tabs-{@ID}">
 <p><xsl:value-of select="@Body" /></p>
 </div>

How can I split the output into two separate DIVs that will place the title's of each list item together in one block while the Body fields of each list item together in a subsequent block?

I thought that using a grouping method would work, but all of my testing and research lends me to think that grouping is effective if there were multiple items with the same Title field (which there will not be).

Any assistance or help pointing me in the right direction would be greatly appreciated. Thank you!

2

The sage Marc Anderson has a blog post about this already. I've used it several times and works wonderfully.

<xsl:template name="dvt_1">
  <xsl:variable name="dvt_StyleName">Table</xsl:variable>
  <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
  <xsl:variable name="dvt_RowCount" select="count($Rows)" />
  <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0" />
  <xsl:choose>
    <xsl:when test="$dvt_IsEmpty">
      <xsl:call-template name="dvt_1.empty" />
    </xsl:when>
    <xsl:otherwise>
        <div id="tabs">
          <xsl:call-template name="tabsList">
            <xsl:with-param name="Rows" select="$Rows" />
          </xsl:call-template>
          <xsl:call-template name="tabsPanels">
            <xsl:with-param name="Rows" select="$Rows" />
          </xsl:call-template>
        </div>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="tabsList">
  <xsl:param name="Rows" />
  <ul>
    <xsl:for-each select="$Rows">
      <li><a href="{concat('#tabs-',@ID)}"><xsl:value-of select="@Title" /></a></li>
    </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template name="tabsPanels">
  <xsl:param name="Rows" />
  <xsl:for-each select="$Rows">
    <div id="{concat('tabs-',@ID)}">
      <xsl:value-of select="@panelText" disable-output-escaping="yes" />
    </div>
  </xsl:for-each>
</xsl:template>

<xsl:template name="dvt_1.empty">
  <xsl:variable name="dvt_ViewEmptyText">No items.</xsl:variable>
  <table border="0" width="100%">
    <tr>
      <td class="ms-vb">
        <xsl:value-of select="$dvt_ViewEmptyText" />
      </td>
    </tr>
  </table>
</xsl:template>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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