XSLT - 使用参数调用模板

时间:2014-01-23 17:59:17

标签: templates xslt parameters

你能帮助我更好地理解代码的这一部分:

调用'template1'时,会发送哪些参数以及哪些值?我的理解是参数'xValue'被发送到模板,但我不理解<xsl:param name="xValue" select="0"/>。调用模板后的两个条件是否确定要发送的参数的值?

<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>

2 个答案:

答案 0 :(得分:1)

<xsl:param name="xValue" select="0"/>正在定义一个名为xValue的参数,其默认值为0

<xsl:with-param name="xValue">中使用xsl:call-template时,您将覆盖该默认值。

答案 1 :(得分:1)

  

我不理解<xsl:param name="xValue" select="0"/>

这将“0”定义为xValue参数的默认值。如果使用显式指定的其他值调用模板(就像在示例中那样),则会覆盖默认值。

  

调用模板后的两个条件是否确定   要发送的参数的值?

是。更确切地说,一个选择语句确定要发送的值;根据测试结果,它有一个测试和两个可供选择的值。