Subject: [xsl] Passing parameters to an indirectly called template after matching. From: Kannan <riderchap@xxxxxxxxx> Date: Thu, 17 Apr 2008 06:33:44 -0400 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Create XML, IZASKUN GUTIERREZ GU | Thread | Re: [xsl] Passing parameters to an , Martin Honnen |
[xsl] Create XML, IZASKUN GUTIERREZ GU | Date | Re: [xsl] Cannot process a result t, ALEXCONTINI@xxxxxxxx |
Month |