Jdreamer
Jdreamer

Reputation: 61

XSL: Issue with calling a template

I have a pretty simple XSL template which I call from inside an another template:

<xsl:call-template name="warningsTemplate">
                              <xsl:with-param name="ColName" select="Test Description" />
                            </xsl:call-template>

Template:

 <xsl:template name="warningsTemplate">
    <xsl:param name="ColName"/>
    <xsl:for-each select="RejRow[count(Col/ValidationType)!=0]">
      <tr>
        <xsl:for-each select="Col[ColName=$ColName]">
          <xsl:choose>
            <xsl:when test="ValidationType='$ColName: Non-Numeric'">
              <td class="warningTd">
                <span class="warningRed">
                  <xsl:value-of select="ColValue"/>
                </span>
              </td>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </xsl:template>

When I call this template, it is showing an error on word "Description" :

System.Xml.Xsl.XslTransformException: Expected end of the expression, found 'Description'.

What is wrong here?

Upvotes: 0

Views: 125

Answers (1)

Tim C
Tim C

Reputation: 70618

The select attribute of xsl:with-param expects an expression. If you are trying to pass a text string, you need to wrap the value in apostrophes, like so:

<xsl:with-param name="ColName" select="'Test Description'" />

(Note, if you had done <xsl:with-param name="ColName" select="Test" />, for example, then you wouldn't have got an error. Although you would not have got the results you had expected either, as in this case it would have been looking for an element named Test in your XML.)

Also, note that the following expression is not going to work for you:

<xsl:when test="ValidationType='$ColName: Non-Numeric'">

Here it will literally look for a string "$ColName: Non-Numeric". It is not going to evaluate "$ColName" as a variable inside the string. You need to do this...

<xsl:when test="ValidationType=concat($ColName, ': Non-Numeric')">

Upvotes: 1

Related Questions