Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2004, 08:19 PM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a parameter into the XSLT thru a link

]
I am new to XSLT, and I need help with passing a parameter into the XSLT based on a link.

Here is what I am trying to do:

I need to build a dynamic navigation tree.
On a client-side transformation, using MSXML, I would like to use one XML file with one XSL stylesheet to get my HTML, but I need the output to depend on (a parameter) the link that is selected.

Here is a Sample XML:

<categories>
    <category name="Jewelry" link="jewelry">
        <level name="Gold" link="#">
            <sublevel name="Rings" link="#"/>
            <sublevel name="Watches" link="#"/>
            <sublevel name="More..." link="#"/>
        </level>
        <level name="Silver" link="#">
            <sublevel name="Rings" link="#"/>
            <sublevel name="Watches" link="#"/>
            <sublevel name="More..." link="#"/>
        </level>
     </category>
    <category name="Computers & Electronics" link="#">
        <level name="Computers" link="#">
            <sublevel name="Desktops" link="#"/>
            <sublevel name="Laptops" link="#"/>
        </level>
        <level name="Electronics" link="#">
            <sublevel name="Stereos" link="#"/>
            <sublevel name="Televisions" link="#"/>
        </level>
    </category>
    <category name="Art & Antiques" link="#">
        <level name="Art" link="#">
            <sublevel name="Paintings" link="#"/>
            <sublevel name="Posters" link="#"/>
            <sublevel name="More..." link="#"/>
        </level>
         <level name="Antiques" link="#"></level>
     </category>
</categories>

And what I want to happen is to have a list of all the CATEGORY names in HTML like so:

<p><a href="#">Jewelery</a></p>
<p><a href="#">Computers & Electronics</a></p>
<p><a href="#">Art & Antiques</a></p>

But, when you click on say Jewelry link, I only want the information about the LEVELs inside the Jewelry category to show up in the HTML, and nothing else, like so:

<p><a href="#">Jewelery</a>
    [list]
<li><a href="#">Gold</a></li>
<li><a href="#">Silver</a></li>
    </ul>
</p>
<p><a href="#">Computers & Electronics</a></p>
<p><a href="#">Art & Antiques</a></p>

And, if you click further, lets say on Gold, I would want only Gold to expand like so:

<p><a href="#">Jewelery</a>
    [list]
<li><a href="#">Gold</a>
    [list]
    <li><a href="#">Rings</a></li>
<li><a href="#">Watches</a></li>
<li><a href="#">more…</a></li>
    </ul>
</li>
<li><a href="#">Silver</a></li>
    </ul>
</p>
<p><a href="#">Computers & Electronics</a></p>
<p><a href="#">Art & Antiques</a></p>


I am not sure how to create my XSL stylesheet so that I can use only one XML file that has the information about all the CATEGORIES, and transform it so that only the information that I want is output into the HTML.

Here is a sample stylesheet with Parameters set up:

<xsl:param name="category" select="'Computers'" />
<xsl:param name="level" select="'Electronics'" />

    <xsl:template match="categories/category">
    <xsl:variable name="showLevel" select="starts-with(@name, $category)" />
        <xsl:for-each select=".">
            <p>
                <a href="{@link}">
                    <xsl:value-of select="@name" />
                </a>
                <xsl:choose>
                    <xsl:when test="$showLevel">
                        [list]
                            <xsl:apply-templates select="level" />
                        </ul>
                    </xsl:when>
                    <xsl:otherwise />
                </xsl:choose>
            </p>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="level">
    <xsl:variable name="showSublevel" select="starts-with(@name, $level)" />
        <xsl:for-each select=".">
                <li><a href="{@link}"><xsl:value-of select="@name"/></a>
                    <xsl:choose>
                        <xsl:when test="$showSublevel">
                            <xsl:choose>
                                <xsl:when test="sublevel">
                                    [list]
                                    <xsl:apply-templates select="sublevel" />
                                    </ul>
                                </xsl:when>
                                <xsl:otherwise />
                            </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise />
                    </xsl:choose>
                </li>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="sublevel">
        <xsl:for-each select=".">
            <li><a href="{@link}"><xsl:value-of select="@name"/></a></li>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

I am not sure where to go from here. How can I pass the parameter into my XSL based on the link?
I probably have to use JavaScript to pass the parameter, but not sure how.

Or is there another way?

Any help would be greatly appreciated.

Thank you,
LISKA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameter from javascript to xslt !! suersh79 XSLT 3 November 17th, 2006 03:08 AM
Pass a parameter in a link jmss66 Classic ASP Basics 1 October 20th, 2006 02:23 PM
passing parameter sarah lee ASP.NET 1.0 and 1.1 Basics 3 September 5th, 2006 04:29 PM
Problem in passing parameter to xslt template uttamgarg XSLT 0 April 20th, 2006 09:53 AM
Passing login through link?? mariakovacs Classic ASP Professional 7 December 19th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.