Saber Saber - 3 months ago 8
CSS Question

Having two "param" in one template

I wonder two know that is it possible to bring two

param
inside template? and if so how? For example as this one:

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


and calling:

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


As you see in some position I need year parameter and in others not.

Ps. The reason to use two parameter is that I do not want to duplicate the code.

Answer

I am not sure what exactly your question is. I am quite sure your named template needs to be changed, because you cannot have xsl:with-param as child of xsl:if.

I think that instead of:

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

you should have:

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

or simply:

<xsl:if test="$withYear">
    <xsl:text>.</xsl:text>
    <xsl:value-of select="$year"/>
</xsl:if>
Comments