Thursday, July 10, 2008

XSLT <xsl:with-param> Element

The <xsl:with-param> element defines the value of a parameter to be passed into a template.

Note: The <xsl:with-param> element is allowed within <xsl:apply-templates> and <xsl:call-template>.

Note: The value of the name attribute of <xsl:with-param> must match a name in an <xsl:param> element (the <xsl:with-param> element is ignored if there is no match).

Here is a real example from my project.
<xsl:call-template name="voucherTableTitle">
<xsl:with-param name="typeValue" select="'stopped'"/>
<xsl:with-param name="title" select="'Stopped Vouchers'"/>

<xsl:template name="voucherTableTitle">
<xsl:param name="typeValue" />
<xsl:param name="title" />

<fo:inline><xsl:value-of select="$title"/></fo:inline>

<xsl:call-template name="voucherTable">
<xsl:with-param name="typeValue" select="$typeValue"/>

<xsl:template name="voucherTable">
<xsl:param name="typeValue" />
<xsl:if test="FIELD[FNAME='type' and VALUE=$typeValue]">

With element <xsl:with-param> we can transfer parameters into one template, just like we transfer parameters into one function of one java class.

No comments:

Post a Comment