0

I have a SharePoint DVWP that is using a List as its Data Source. Within this list I two columns - LinkSection and SubSection

Within this DVWP I have "Sections" that group the items in this list. Up until now, each Section has only filtered by one column - see example of one section:

    <xsl:template name="dvt_1">
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    <xsl:variable name="Rows1" select="/dsQueryResponse/Rows/Row[contains(@LinkSection,'Training')]"/>
        <div class="page_home" style=" height: 120px; overflow: hidden; z-index: 0;border:1px solid #CCCCCC;">
        <div class="cat_heading" style="padding: 5px 10px; text-align: left; ">
        <h2 style="font-weight:bold">
        <a title="Section 1">Section 1</a>
        </h2>
        </div>
            <div class="cat_imglinks" style=" height: 70px; overflow: hidden;">
            <div class="cat_img" style="text-align: left; vertical-align: middle;">
            <a> 
                 <span style="width: 78%; float: left;">Section 1 Text</span>
            </a>    
            </div> 
            <div class="panel cat_links">
                <ul>                                
                <xsl:for-each select="$Rows1">          
                <li><a href="{@Link}" title="{@Title}">
                <xsl:value-of select="@Title" disable-output-escaping="yes"/></a></li>          
                </xsl:for-each>
                </ul>
                </div>
            </div>
        </div>                  
    </xsl:template>

I have a request now to filter by two columns. I do not have much experience with XSLT so I am trying things I have seen on forums such as this with no luck.

So, I want to create an AND filter for two Rows - see one of the ways I have tried below. I have tried using the "|" operator in the xsl:for-each line but this seems to display all items meeting the $Rows1 result.

    <xsl:template name="dvt_1">
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    <xsl:variable name="Rows1" select="/dsQueryResponse/Rows/Row[contains(@LinkSection,'Training')]"/>
    <xsl:variable name="Rows2" select="/dsQueryResponse/Rows/Row[contains(@SubSection,'Education')]"/>
        <div class="page_home" style=" height: 120px; overflow: hidden; z-index: 0;border:1px solid #CCCCCC;">
        <div class="cat_heading" style="padding: 5px 10px; text-align: left; ">
        <h2 style="font-weight:bold">
        <a title="Section 1">Section 1</a>
        </h2>
        </div>
            <div class="cat_imglinks" style=" height: 70px; overflow: hidden;">
            <div class="cat_img" style="text-align: left; vertical-align: middle;">
            <a> 
                 <span style="width: 78%; float: left;">Section 1 Text</span>
            </a>    
            </div> 
            <div class="panel cat_links">
                <ul>                                
                <xsl:for-each select="$Rows1 | $Rows2">         
                <li><a href="{@Link}" title="{@Title}">
                <xsl:value-of select="@Title" disable-output-escaping="yes"/></a></li>          
                </xsl:for-each>
                </ul>
                </div>
            </div>
        </div>                  
    </xsl:template>

Any help would be greatly appreciated. Thanks!

Kelsnz
  • 5
  • 2
  • You cannot use an AND operator in a select attribute, you're currently doing a union with |. Can you provide some example XML, input and desired output, also what XSLT version are you using? – griv Sep 02 '22 at 02:17
  • @GRIV - The result is rendered in SharePoint so I'm not sure how to get XML? Sorry for my lack of understanding as I normally don't work with XSL - just in this instance. The input is two columns which are choice columns and the output is the to filter these depending upon the choices made. I don't know if that answers your question? As the Version - again, I'm not sure who to identify that... This is the info when inserting the DVWP - does this help? – Kelsnz Sep 02 '22 at 03:16
  • version="1.0", thanks. Some sample input XML and expected output would be preferred as well. – griv Sep 02 '22 at 03:22
  • Okay @GRIV - I have the XML - am I able to upload the file? I can't paste in this reply -its too long – Kelsnz Sep 02 '22 at 04:29
  • Thanks for your help @GRIV - Bryn gave me what I was after – Kelsnz Sep 02 '22 at 04:54
  • No problem. Awesome. Glad you got what you were looking for. Be sure to tag the XSLT version in your future questions. :). Also, for large files, I’d suggest just isolating a piece of the file to paste into stack overflow and what you expect the results to be/some XSLT you tried. – griv Sep 02 '22 at 05:43
  • Just FYI, the `|` operator creates a **union** of the two sets, which the equivalent of a logical OR. In order to produce a logical AND, you need an **intersection** which is kind of awkward to do in XSLT 1.0: ``. – michael.hor257k Sep 02 '22 at 05:53
  • "I do not have much experience with XSLT so I am trying things I have seen on forums such as this with no luck." That really isn't a good way to learn a new language. Get yourself a good book, or find a good tutorial, and work your way through it. – Michael Kay Sep 02 '22 at 07:11

1 Answers1

0

You currently have 2 variables:

<xsl:variable name="Rows1" select="/dsQueryResponse/Rows/Row[contains(@LinkSection,'Training')]"/>
<xsl:variable name="Rows2" select="/dsQueryResponse/Rows/Row[contains(@SubSection,'Education')]"/>

Instead of adding 'Rows2', just change 'Rows1' to:

<xsl:variable name="Rows1" select="/dsQueryResponse/Rows/Row[contains(@LinkSection,'Training')][contains(@SubSection,'Education')]"/>

Then change your for-each back to:

<xsl:for-each select="$Rows1">  
Bryn Lewis
  • 580
  • 1
  • 5
  • 14