user2144555
user2144555

Reputation: 1313

XSLT - Call a template with parameters

Can you help me to better understand this part of the code:

When 'template1' is called, what parameters are sent and with which values? What I understand is that the parameter 'xValue' is sent to template, but I don't understand the <xsl:param name="xValue" select="0"/>. Are the two conditions after the template is called to determine the value of the parameter to send?

<xsl:call-template name="template1">
    <xsl:with-param name="xValue">
        <xsl:choose>
            <xsl:when test="string-length($var1)=1 ">
                 ...
            </xsl:when>
            <xsl:otherwise>
                 ...
             </xsl:otherwise>
         </xsl:choose>
     </xsl:with-param>
</xsl:call-template>


<xsl:template name="template1">
    <xsl:param name="xValue" select="0"/>
    <xsl:param name="yValue" select="0"/>
    <xsl:variable name="newValue">
      <xsl:variable name="char" select="substring($xValue,1,1)"/>
      <xsl:choose>
        <xsl:when test="matches(upper-case($char),'[A-F]')">
          ...
        </xsl:when>
        <xsl:otherwise>
          ...
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="not(string-length($xValue) = 1)">
          ...
      </xsl:when>
      <xsl:otherwise>
          ...
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Upvotes: 0

Views: 2367

Answers (2)

michael.hor257k
michael.hor257k

Reputation: 116959

I don't understand the <xsl:param name="xValue" select="0"/>.

This defines "0" as the default value for the xValue parameter. If you call the template with a different value specified explicitly (as you do in your example), the default value is overridden.

Are the two conditions after the template is called to determine the value of the parameter to send?

Yes. More precisely, there is one choose statement that determines the value to be sent; it has one test and two values to choose from, according to the result of the test.

Upvotes: 1

Daniel Haley
Daniel Haley

Reputation: 52848

<xsl:param name="xValue" select="0"/> is defining a parameter named xValue with a default value of 0.

When you use <xsl:with-param name="xValue"> in your xsl:call-template, you're overriding that default value.

Upvotes: 1

Related Questions