Please explain me how best XSLT param can be used.
in terms of <xsl:param> & <xsl:with-param>
Sample LOC:
<xsl:call-template name="ABC">
<xsl:with-param name="title" />
</xsl:call-template>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
<xsl:param>can be specified at the global level anywhere (as a child ofxsl:stylesheet) or if it is within a template, it must be its child and it must precede any non-xsl:paramchild ofxsl:template.This is the facility that allows a template or the whole transformation (in case of a global
xsl:param) to receive varying data from the caller/initiator of the template or of the whole transformation, respectively.On the side of the caller/initiator of the template/transformation, parameters are passed by using an
xsl:with-paraminstruction. it can be a child ofxsl:apply-templatesorxsl:call-template.The
nameattribute of eitherxsl:paramorxsl:with-paramis mandatory. It identifies the parameter.The select attribute of
xsl:with-parammay be used to specify any XPath expression, the result of whose evaluation is passed to the called/applied template.Alternatively, the value can be specified in the content (body) of
xsl:with-param.xsl:with-parammust have either aselectattribute or a body. but not both of them.An
xsl:paramcan also have a select attribute or body. In this case, these specify the default value of the parameter and it is used if no parameter with this name has been specified by the caller.Finally, here is a complete example illustrating most of these concepts:
When applied on this XML document…
…the result is…
Explanation:
The
replacetemplate is called twice. In both calls thepTextparameter is omitted. Its default value is used by the called template.The first call provides the pattern and replacement parameters, so
"love"is replaced by"like".Do note that the values of the global parameters
$pTargetand$pReplacementare passed through. If the initiator of the transformation decides to pass other values (not the defaults that are used in this code) for these global parameters, these values will be passed to thereplacetemplate and not the defaults"love"and"like".The second call doesn’t provide any parameter values at all, so all defaults in the
replacetemplate are used — the string"hate"is replaced by the string"disapprove".Note that the
replacetemplate calls itself recursively, so that all occurrences of the pattern are replaced by the replacement.Also, the values of the
pTextparameter of the recursive calls aren’t static, but are dynamically calculated.The third time the
replacetemplate is initiated from outside is viaxsl:apply-templates. Here we also show that a template can have both amatchand anameattribute at the same time and it is possible that such a template can be initiated both usingxsl:apply-templatesandxsl:call-template.