Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xslt

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

like image 972
bouncingHippo Avatar asked Aug 03 '12 20:08

bouncingHippo


2 Answers

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;
like image 200
Jim Garrison Avatar answered Oct 21 '22 01:10

Jim Garrison


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>
like image 39
Dimitre Novatchev Avatar answered Oct 21 '22 03:10

Dimitre Novatchev