[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Passing parameters to an indirectly called template af

Subject: Passing parameters to an indirectly called template after matching.
From: Kannan <riderchap@xxxxxxxxx>
Date: Thu, 17 Apr 2008 06:33:44 -0400
 Passing parameters to an indirectly called template af
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="&quot;'&quot;"/>
            <xsl:with-param name="replacementString" select="&quot;''&quot;"/>
        </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="&quot;'&quot;"/>
      <xsl:variable name="replacementString" select="&quot;''&quot;"/>

    <!-- 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.