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

Need a hand formatting some XSL. Taking a look at an example that Marc Anderson put together for a jquery accordion, I need to tweak the output. I've been playing with this for quite a while and can't seem to get it to do what I tell it to (or what I want it to).

Here's the XSL...

 <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema"
    xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"       xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
  <xsl:call-template name="AccordionSetup"/>
</xsl:template>

<xsl:template name="AccordionSetup">
  <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
  <div id="left-accordion" style="width: 300px;">
    <ul>       
      <xsl:for-each select="$Rows">
      <xsl:sort select="@AccHeading_x003a_Order" data-type="number"/>
      <xsl:sort select="@Order" data-type="number"/>
      <xsl:call-template name="AccordionPanels">
        <xsl:with-param name="Rows" select="$Rows"/>
      </xsl:call-template>
    </xsl:for-each>
    </ul>
  </div>
</xsl:template>

<xsl:template name="AccordionPanels">
  <xsl:param name="Rows"/>
  <xsl:variable name="NewHeading" select="ddwrt:NameChanged(string(@AccHeading.), 0)"/>
  <xsl:if test="string-length($NewHeading) &gt; 0">
    <li>
      <a href="#{substring-before(@AccHeading., ';#')}">
        <xsl:value-of select="substring-after(@AccHeading., ';#')"/>
      </a>
    </li>
    <div>
      <ul>
        <xsl:variable name="PanelRows" select="$Rows[@AccHeading. = current()/@AccHeading.]"/>
        <xsl:for-each select="$PanelRows">
          <xsl:call-template name="AccordionPanelContent"></xsl:call-template>
        </xsl:for-each>
      </ul>
    </div>
  </xsl:if>
</xsl:template>

<xsl:template name="AccordionPanelContent">
  <li>
    <xsl:value-of select="@Title"/> - <a href="{@ContentLink}"><xsl:value-of select="@ContentLink.desc"/></a>
  </li>
</xsl:template>

The output of the above results in the following formatting

<div id="accordion">
<ul>
<li><a href="#">First header</a></li>
<div>First content</div>
<li><a href="#">Second header</a></li>
<div>Second content</div>
</ul>
</div>

What I need is for the output to be as such.......

 <div id="accordion">
    <ul>
       <li><a href="#">First header</a></li>
       <li><a href="#">Second header</a></li>
   </ul>
    <div>First content</div>
    <div>Second content</div>

    </div>
share|improve this question
    
Are you able to share final solution. I am trying to achieve this using the content query webpart and will appreciate your knowledge on this. –  Mighty Jun 7 '12 at 21:51

2 Answers 2

up vote 1 down vote accepted

Here is a quick and dirty, untested, solution that "should" work. If I had a bit more time, I could probably provide a more elegant solution.

I'll admit I didn't look, too closely at the code, so hopefully it will at least get you started in the right direction.

 <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" 
    xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"       xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls"> 
  <xsl:call-template name="AccordionSetup"/> 
</xsl:template> 

<xsl:template name="AccordionSetup"> 
  <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/> 
  <div id="left-accordion" style="width: 300px;"> 
    <ul>        
      <xsl:for-each select="$Rows"> 
      <xsl:sort select="@AccHeading_x003a_Order" data-type="number"/> 
      <xsl:sort select="@Order" data-type="number"/> 
      <xsl:call-template name="AccordionHeaders"> 
        <xsl:with-param name="Rows" select="$Rows"/> 
      </xsl:call-template> 
    </xsl:for-each>
    </ul> 
      <xsl:for-each select="$Rows"> 
      <xsl:sort select="@AccHeading_x003a_Order" data-type="number"/> 
      <xsl:sort select="@Order" data-type="number"/> 
      <xsl:call-template name="AccordionContent"> 
        <xsl:with-param name="Rows" select="$Rows"/> 
      </xsl:call-template> 
    </xsl:for-each>    
  </div> 
</xsl:template> 

<xsl:template name="AccordionHeaders"> 
  <xsl:param name="Rows"/> 
  <xsl:variable name="NewHeading" select="ddwrt:NameChanged(string(@AccHeading.), 0)"/> 
  <xsl:if test="string-length($NewHeading) &gt; 0"> 
    <li> 
      <a href="#{substring-before(@AccHeading., ';#')}"> 
        <xsl:value-of select="substring-after(@AccHeading., ';#')"/> 
      </a> 
    </li> 
  </xsl:if> 
</xsl:template> 

<xsl:template name="AccordionContent"> 
  <xsl:param name="Rows"/> 
  <xsl:variable name="NewHeading" select="ddwrt:NameChanged(string(@AccHeading.), 0)"/> 
  <xsl:if test="string-length($NewHeading) &gt; 0"> 
    <div> 
      <ul> 
        <xsl:variable name="PanelRows" select="$Rows[@AccHeading. = current()/@AccHeading.]"/> 
        <xsl:for-each select="$PanelRows"> 
          <xsl:call-template name="AccordionPanelContent"></xsl:call-template> 
        </xsl:for-each> 
      </ul> 
    </div> 
  </xsl:if> 
</xsl:template> 



<xsl:template name="AccordionPanelContent"> 
  <li> 
    <xsl:value-of select="@Title"/> - <a href="{@ContentLink}"><xsl:value-of select="@ContentLink.desc"/></a> 
  </li> 
</xsl:template> 
share|improve this answer
    
I actually ended up getting this figured out with a very similar setup. Yours was a little better. Thank you very much! –  CeeMoney May 2 '12 at 1:33

Check the jqueryUI documentation. What the .accordion() function wants to see in the markup is something like this:

<div id="accordion">
  <h3><a href="#">First header</a></h3>
  <div>First content</div>
  <h3><a href="#">Second header</a></h3>
  <div>Second content</div>
</div>
share|improve this answer
    
I'm not actually using the jqueryui accordion but rather a different widget, so the formatting mentioned above is necessary. Your example was actually a good base. The tweaking of the xsl is the tough part of course :) –  CeeMoney Apr 30 '12 at 22:54

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.