bouncingHippo
bouncingHippo

Reputation: 6040

passing a string param from xsl:template and using it in another xsl file

<xsl:template match="HtmlCode">
    <xsl:copy-of select="child::*|text()"/>
</xsl:template>

<xsl:call-template name="HappyFriend">
    <xsl:with-param name="text" select="'i am a friggin' RRRRROOOOOOOVVVERRRRR~~'"/>
</xsl:call-template> 

<xsl:template name="HappyFriend">
        <xsl:param name="text"/>
        <HtmlCode>
            &lt;span&gt; &lt;%="text"%&gt;   &lt;/span&gt;
        </HtmlCode>
<xsl:template>

somehow i keep getting XSLT issues...all i am trying to do is to get the value of the variable "text" which is "i am a frigggin RRROVERRR" to appear into a i am a frigggggin' RRROOOVVVERRRR~~ in the "HappyFriend" template.

What am i doing wrong?

Upvotes: 6

Views: 21364

Answers (3)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

Here is one correct way to do what I guess you want:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="HtmlCode">
        <xsl:copy-of select="child::*|text()"/>
        <xsl:call-template name="HappyFriend">
            <xsl:with-param name="text" select='"i am a friggin&apos; RRRRROOOOOOOVVVERRRRR~~"'/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="HappyFriend">
        <xsl:param name="text"/>
        <HtmlCode>
          <span><xsl:value-of select="$text"/></span>
    </HtmlCode>
    </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the following XML document (none has been provided!!!):

<HtmlCode/>

The wanted, correct result is produced:

<HtmlCode>
   <span>i am a friggin' RRRRROOOOOOOVVVERRRRR~~</span>
</HtmlCode>

Upvotes: 2

Jim Garrison
Jim Garrison

Reputation: 86774

Several problems:

-- The string literal 'i am a friggin' RRRRROOOOOOOVVVERRRRR~~' contains unbalanced single quotes. You probably want

<xsl:with-param name="text" select='"i am a friggin&#x27; RRRRROOOOOOOVVVERRRRR~~"'/>

-- The call-template cannot occur outside of a template definition.

-- To refer to the parameter you should be using value-of-select, as in

 &lt;span&gt; &lt;%="<xsl:value-of select="$text"/>"%&gt;   &lt;/span&gt;

Upvotes: 10

rene
rene

Reputation: 42444

see the FAQ for parameters

   <xsl:template name="HappyFriend"> 
         <xsl:param name="text"/> 
         <HtmlCode> 
             <span> 
                <xsl:value-of select="$text"/> 
             </span> 
        </HtmlCode>  
     <xsl:template>

Upvotes: 1

Related Questions