It looks as if you are looking for the XSLT 2.0 facility of "tunnel
parameters".
http://www.w3.org/TR/xslt20/#tunnel-params
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Kannan [mailto:riderchap(_at_)gmail(_dot_)com]
Sent: 17 April 2008 11:34
To: xsl-list
Subject: [xsl] Passing parameters to an indirectly called
template after matching.
Hello group,
I have a string replacement function. Also I have many
XSL files that need to make use of the replace functionality.
I found there is an include directive to include an XSL in
another XSL. So that from each XSL file I can call the
replacement function with necessary parameters. My problem is
that I am not able to 'propagate' my parameters from the
template calling point to the template that actually doing
the string replacement.
I am calling the a template that resides in the string
replacement XSL, from another XSL file like this for e.g..
<!-- In file caller.xsl -->
<xsl:include href="replaceXSL.xsl"/>
<xsl:template match="ATag">
<xsl:call-template name="ReplaceInXMLString">
<xsl:with-param name="theNodeMatch" select="./*"/>
<xsl:with-param name="stringToBeReplaced"
select=""'""/>
<xsl:with-param name="replacementString"
select=""''""/>
</xsl:call-template>
</xsl:template>
<!--End-->
And in replaceXSL.xsl file, now I have two global
variables (for "stringToBeReplaced" and "replacementString"
), I don't want to use these global variables, so that I can
make my replacement functionality generic. How do I
"propagate" the parameters passed ("stringToBeReplaced" and
"replacementString") from the client called template
"ReplaceInXMLString" to the template which doing the
replacement functionality (the "ReplaceString" template.)
<!-- In file replaceXSL.xsl -->
<!-- The globals I want to get rid of. -->
<xsl:variable name="stringToBeReplaced" select=""'""/>
<xsl:variable name="replacementString" select=""''""/>
<!-- This is the template the client calls. -->
<xsl:template name="ReplaceInXMLString">
<xsl:param name="theTagMatch"/>
<xsl:apply-templates select="msxsl:node-set(
$theTagMatch)"/>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name()}">
<xsl:call-template name="ReplaceString">
<xsl:with-param name="stringInContext" select="."/>
<xsl:with-param name="stringToBeReplaced"
select="$stringToBeReplaced"/>
<xsl:with-param name="replacementString"
select="$replacementString"/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template match="text()">
<xsl:call-template name="ReplaceString">
<xsl:with-param name="stringInContext" select="."/>
<xsl:with-param name="stringToBeReplaced"
select="$stringToBeReplaced"/>
<xsl:with-param name="replacementString"
select="$replacementString"/>
</xsl:call-template>
</xsl:template>
<!-- Here is where I want the parameters I actually passed to the
template ReplaceInXMLString -->
<xsl:template name="ReplaceString">
<xsl:param name="stringInContext"/>
<xsl:param name="stringToBeReplaced"/>
<xsl:param name="replacementString"/>
<xsl:choose>
<xsl:when test="contains($stringInContext ,
$stringToBeReplaced)">
<xsl:value-of
select="concat(substring-before($stringInContext,
$stringToBeReplaced),$replacementString)"/>
<xsl:call-template name="ReplaceString">
<xsl:with-param name="stringInContext"
select="substring-after($stringInContext,$stringToBeReplaced)"/>
<xsl:with-param name="stringToBeReplaced"
select="$stringToBeReplaced"/>
<xsl:with-param name="replacementString"
select="$replacementString"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$stringInContext"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- End -->
Thank you for your time. Any help greatly appreciated.
Thanks,
Kannan
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--