Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2009, 11:34 PM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sharepoint itemstyle.xsl query

Hey guys.
I am writing an xslt template to display a 3 column table display of items from a sharepoint list.
I have this set up fine. It uses the $CurrentPosition and mod mathematical function to determine when to close the row and insert a new one.

My issue now is that I want to put 'sub categories' under some of the items in the table.
I have it all set up perfectly, and I have built the template so it can discern between a category and a sub category (based on the LinkUrl variable that is passed in). My problem is that it still increments the $CurrentPosition variable for every item.

Is there a way to prevent it from incrementing this variable on a specific condition? Or can I store a variable outside the template (ie in java script) that holds the amount of sub-categories found then my row determinated function can be something like ($CurrentPosition - $NoSubCategories) mod 3.

Any help would be apperciated.
Chris
 
Old June 16th, 2009, 02:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show a small example of the XML input and the desired output, alongside the XSLT that you have now?
__________________
Joe
http://joe.fawcett.name/
 
Old June 16th, 2009, 03:02 AM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not using XML. In sharepoint (A Microsoft CMS application), it uses xsl stylesheets to render a display of items in a list.

In my case, this list is a directory structure, with folders and sub folders (representing categories and sub-categories).

Basically where it runs :
Code:
 <xsl:when test="normalize-space($thirdTier)">
                        <xsl:value-of select="$thirdTier" />
                        <xsl:text> THIS IS A SUB CATEGORY - </xsl:text>
                        <xsl:text>   Current Position = </xsl:text><xsl:value-of select="$CurPos"></xsl:value-of><![CDATA[<br></br>]]>
                    </xsl:when>
I need to implement something so that it doesn't increment the current position parameter.

Here is my current XSLT:

Code:
<xsl:template name="MulticolumnBusinessDirectory" match="Row[@Style='MulticolumnBusinessDirectory']" mode="itemstyle">
<xsl:param name="CurPos" /> 
<xsl:param name="Last" /> 
        <xsl:variable name="thirdTier">
            <xsl:value-of select="substring-after(substring-after(substring-after(@LinkUrl, 'Community Directory'),'/'),'/')" />
        </xsl:variable>
        <xsl:variable name="tableStart"> 
                <xsl:if test="$CurPos = 1">
                <![CDATA[<table width="100%" border="1" cellpadding="0" cellspacing="0">]]> 
                </xsl:if> 
             </xsl:variable>
            <xsl:variable name="tableEnd"> 
            <xsl:if test="$CurPos = $Last"> 
                <![CDATA[</table>]]> 
                </xsl:if> 
            </xsl:variable>
            <xsl:variable name="tableRowItem">
            <xsl:choose>
                    <xsl:when test="normalize-space($thirdTier)">
                        <xsl:value-of select="$thirdTier" />
                        <xsl:text> THIS IS A SUB CATEGORY - </xsl:text>
                        <xsl:text>   Current Position = </xsl:text><xsl:value-of select="$CurPos"></xsl:value-of><![CDATA[<br></br>]]>
                    </xsl:when> 
                    <xsl:otherwise>
                        <![CDATA[</td><td>]]>
                &lt;a href="<xsl:value-of select="@Title"/>">
                <xsl:value-of select="@Title"/>
                &lt;/a>
                <xsl:text> THIS IS A MAIN CATEGORY - </xsl:text>
                <xsl:text>   Current Position = </xsl:text><xsl:value-of select="$CurPos"></xsl:value-of><![CDATA[<br></br>]]>
                    </xsl:otherwise>    
            </xsl:choose>
            </xsl:variable>        
        <xsl:variable name="tableRow">
            <xsl:choose>
                <xsl:when test="$CurPos mod 3 = 1">
                    <![CDATA[<tr>]]> 
                    <xsl:value-of select="$tableRowItem" disable-output-escaping="yes"/>
                    <xsl:if test="$CurPos = $Last">
                        <![CDATA[<td></td></tr>]]>     
                    </xsl:if>
                 </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                    <xsl:when test="normalize-space($thirdTier)">
                        <xsl:value-of select="$thirdTier" />
                        <xsl:text> THIS IS A SUB CATEGORY - </xsl:text>
                    <xsl:text>   Current Position = </xsl:text><xsl:value-of select="$CurPos"></xsl:value-of><![CDATA[<br></br>]]>
                    </xsl:when> 
                    <xsl:otherwise>
                        <![CDATA[</td><td>]]>
                &lt;a href="<xsl:value-of select="@Title"/>">
                <xsl:value-of select="@Title"/>
                &lt;/a>
                <xsl:text> THIS IS A MAIN CATEGORY - </xsl:text>
                <xsl:text>   Current Position = </xsl:text><xsl:value-of select="$CurPos"></xsl:value-of><![CDATA[<br></br>]]>
                    </xsl:otherwise>    
                    </xsl:choose>
                </xsl:otherwise>        
            </xsl:choose>
        </xsl:variable>
        <xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
        <xsl:value-of select="$tableRow" disable-output-escaping="yes"/>
        <xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>
        
    </xsl:template>
 
Old June 16th, 2009, 03:19 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't get it to 'not increment' $CurPos as its a parameter passed in to your template.

You also have lots of things in CDATA tags, which is usually a sign that something is very wrong.

Where is the MultiColumnBusinessDirectory called from? You say you are not using XML, yet that is exactly what is being used under the hood.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 16th, 2009, 03:30 AM
Registered User
 
Join Date: Jun 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The multicolumnbusinessdirectory is the name of the template.

Basically the business directory is a list with different columns. As part of creating this list you can specify the xsl file and template name you wish to use to render its data. You then specify the parameters of the list that you wish to pass to the template (in this case, Title, LinkUrl).

So my xsl looks at each item in the list one at a time and does certain actions based on different choose statements.

If it is the first item, it opens up the table (<table border=1 .... )
If it is NOT the first item but is a MAIN CATEGORY, it adds a cell (<td></td>)
If it is NOT the first item but is SUB category, it places it it inside the same cell as the last item processed.
It checks each item with $CurPos mod 3 to determine when it needs to create a new row (as I only want 3 columns in my table).

The issue is that it counts sub categories too (which shouldn't be counted because they are not in a new cell in their row, instead included in the MAIN CATEGORY's cell).

Thanks for your help!
 
Old June 16th, 2009, 05:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Unfortunately that sort of XSLT is based on a lot of examples in SharePoint books. Instead of embracing XSLT's functional and declarative style it imposes a procedural way of doing things by using CDATA sections.

When I use SharePoint I usualy find it better to start with a clean slate, get hold of the XML and develop the XSLT properly.
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:function pass param to attribute of xsl:instruction bonekrusher XSLT 4 March 31st, 2009 09:06 AM
Totalling a column in XSL for Sharepoint Site CarGal XSLT 1 February 26th, 2009 03:28 AM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
XSL - Parameter query. Neal XSLT 4 January 24th, 2006 01:27 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.