Alternative ways to set a variable value in XSLT?

I have a basic XSLT filter in a SharePoint DataFormWebPart:

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>

$ MyParameter comes from an ASP.NET control. But an attempt to set the value of the variable by any other means leads to an error:

<xsl:variable name="Rows">
<xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>
</xsl:variable>

or

<xsl:variable name="Rows">
/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]
</xsl:variable>

The error I get: Argument 1 should return node -set. → count ($ Rows) <-

Ultimately, I try to achieve something similar:

<xsl:variable name="Rows">
<xsl:choose>
  <xsl:when test="($MyParameter2 = '1')">
    <xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$otherParameter)]"/>
  </xsl:otherwise>
</xsl:choose>
</xsl:variable>

Is this possible with XSLT, or should I look for other features in SharePoint Designer?

+3
source share
1 answer

count(), w630 > -set, .

, $Rows, , node -sets.

  • , select node -set XPATH.

  • xsl:value-of . , , node -set, XPATH.

  • xsl:variable, , $Rows. XPATH, . "/dsQueryResponse/Rows/Row [((ddwrt: FormatDateTime ( (@MyDate), 1061," MM ")) = $MyParameter)]" $Rows.

: XPATH select $MyParameter2 :

<xsl:variable name="Rows" 
    select="/dsQueryResponse/Rows/Row[
        ((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter) 
        and $MyParameter2='1'
      ] 
  | 
    /dsQueryResponse/Rows/Row[
        ((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$otherParameter) 
        and $MyParameter2 !=1
       ]" 
 />
+5

Source: https://habr.com/ru/post/1769101/


All Articles