Master345
Master345

Reputation: 2266

Passing XSLT variable from a XSL to another called by a call-template

I have 2 files.

1->index.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!-- Includes -->
    <xsl:include href="navigation.xsl" />
    <xsl:include href="head.xsl" />

    <xsl:template match="/">

    <!-- WANT TO PASS THIS VARIABLE TO navigation.xsl-->
    <xsl:variable name="value" select="1"/>
    <!-- WANT TO PASS THIS VARIABLE TO navigation.xsl-->

    <html>
        <head>
            <!-- Basic -->
            <xsl:call-template name="HtmlBasicHead"/>
            <!-- Seo -->
            <title>Impress</title>
            <meta name="description" content="..." />
            <meta name="keywords" content="..." />
        </head>

        <body>
            <div id="main">

                <xsl:call-template name="Header"/>

                <xsl:call-template name="NavigationMenu"/>

            </div>
        </body>
    </html>

    </xsl:template>

</xsl:stylesheet>

2->navigation.xsl

<xsl:template name="NavigationMenu">
    <!-- NAVIGATION MENU BEGIN -->
    <div id="tray">
    <ul>
        <xsl:if test="$value='1'">
        VALUE IS 1
        </xsl:if>

        <li id="tray-active"><a href="#">Homepage</a></li>
        <li><a href="#">Live demo</a></li>
        <li><a href="#">About product</a></li>
        <li><a href="#">Testimonials</a></li>
        <li><a href="#">Download</a></li>
        <li><a href="#">Purchase</a></li>

    </ul>
    <!-- NAVIGATION MENU END -->
</xsl:template>

What im trying to do is to declare the variable in index.xsl , and still use it in navigation.xsl trough call-template, because i'm getting an error like "Variable 'value' has not been declared. " ....

The reason im doing this is because i need to specify what button should be highlighted.

Thank you!

Upvotes: 1

Views: 2893

Answers (1)

Marian Bazalik
Marian Bazalik

Reputation: 1395

Use xsl:with-param

http://www.w3schools.com/xsl/el_with-param.asp

amend navigation.xsl in following way

<xsl:template name="NavigationMenu">
   <xsl:param name="value" />
   ...

and then call it from index.xsl in this way

<xsl:call-template name="NavigationMenu">
   <xsl:with-param name="value" select="1" />
</xsl:call-template>

Upvotes: 3

Related Questions