Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Wed, 16 Apr 2008 19:55:03 -0700 (PDT),    group: microsoft.public.xsl        back       


Passing parameter to an indirectly called function.   
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,
Kannan
date: Wed, 16 Apr 2008 19:55:03 -0700 (PDT)   author:   unknown

Re: Passing parameter to an indirectly called function.   
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
	http://JavaScript.FAQTs.com/
date: Thu, 17 Apr 2008 13:31:48 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us