在一个模板中有两个“参数”

时间:2016-08-12 08:57:56

标签: html css xslt-1.0

我想知道两个人知道可以在模板中加入两个param吗?如果是这样怎么样?例如,这个:

<xsl:template name="formatDate">
    <xsl:param name="timeParam"/>
    <xsl:param name="withYear"/>
    <xsl:variable name="dateParam" select="substring-before($timeParam,'T')"/>
    <xsl:variable name="year" select="substring($dateParam,1,4)"/>
    <xsl:variable name="month" select="substring($dateParam,6,2)"/>
    <xsl:variable name="day" select="substring($dateParam,9,2)"/>
    <xsl:if test="string-length($day) = 1">
        <xsl:value-of select="'0'"/>
    </xsl:if>
    <xsl:value-of select="$day"/>
    <xsl:value-of select="'.'"/>
    <xsl:if test="string-length($month) = 1">
        <xsl:value-of select="'0'"/>
    </xsl:if>
    <xsl:value-of select="$month"/>

    <xsl:if test="string-length($withYear) = 1">
        <xsl:value-of select="'.'"/>
        <xsl:value-of select="'0'"/>
        <xsl:with-param name="withYear" select="$year" />
    </xsl:if>
</xsl:template>

并致电:

<xsl:call-template name="formatDate">
    <xsl:with-param name="timeParam" select="attribute::time"/>
    <xsl:with-param name="withYear" select="1"/>                    
</xsl:call-template>
<xsl:call-template name="formatDate">
    <xsl:with-param name="timeParam" select="attribute::time"/> 
</xsl:call-template>

正如你在某个位置看到的那样,我需要年份参数,而在其他位置则不需要。

聚苯乙烯。使用两个参数的原因是我不想复制代码。

1 个答案:

答案 0 :(得分:0)

我不确定你的问题到底是什么。我确信您的命名模板需要更改,因为您不能std::move作为xsl:with-param的孩子。

我认为不是:

xsl:if

你应该:

<xsl:if test="string-length($withYear) = 1">
    <xsl:value-of select="'.'"/>
    <xsl:value-of select="'0'"/>
    <xsl:with-param name="withYear" select="$year" />
</xsl:if>

或简单地说:

<xsl:if test="string-length($withYear) = 1">
    <xsl:value-of select="'.'"/>
    <xsl:value-of select="$year"/>
</xsl:if>