|
| Passing parameter to an indirectly called function. |
 |
Wed, 16 Apr 2008 19:55:03 -070 |
Hello group,
I have a string replacement function (thanks to folks in this forum).
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 all your response and your time.
Thanks,
|
| Post Reply
|
| Re: Passing parameter to an indirectly called function. |
 |
Thu, 17 Apr 2008 13:31:48 +020 |
riderchap@gmail.com wrote:
> <xsl:call-template name="ReplaceInXMLString">
> <xsl:with-param name="theNodeMatch"
select="./*"/>
> <xsl:with-param name="stringToBeReplaced"
> select=""'""/>
> <xsl:with-param name="replacementString"
> select=""''""/>
> <xsl:template name="ReplaceInXMLString">
> <xsl:param name="theTagMatch"/>
You need to declare the parameters you want to pass in e.g.
<xsl:param name="stringToBeReplaced"/>
<xsl:param name="replacementString"/>
--
Martin Honnen --- MVP XML
|
| Post Reply
|
|
|
|
|
|
|
|
|
|