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 March 24th, 2006, 01:14 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing parameter to xsl file

I am a newbie to XML/XSL.

I am passing the parameter in the link as you can see in the below html example. All I want is based on the keyname value passed in the link I want to retreive the data from XML file and then display it in the webpage. The below code doesn't seem to work. It is not displaying anything at all.

If I hard code the value for example if I change the following line in XSL file from

<xsl:if test="@id=$keyname"> to
<xsl:if test="@id='ab'">

it works like a charm. Please could someone let me know regarding this.

I have three files HTML/XML/XSL

1. html file has the following line

<a href="http://abcd.xml?keyname=abcd" target="_blank">link</a>

2. abcd.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="abcd.xsl"?>
<mainpackage>
<Package id="123">
  <base id="ab">
</package>
<Package id="456">
  <base id="cd">
</package>
</mainpackage>

3. abcd.xsl

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="keyname"/>
<xsl:template match="/">
  <html>
    <body>
        <xsl:for-each select="mainpackage/Package">
            <xsl:if test="@id=$keyname">
                <xsl:value-of select="Base/@id"/>
            </xsl:if>
        </xsl:for-each>
    </body>
  </html>
</xsl:template>
</xsl:stylesheet>
 
Old March 24th, 2006, 01:24 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You cannot do this using a browsers built in ability to transform via a linked stylesheet as parameters in the query string are not passed on to the XSLT as params.
You will have to have a page that reads the query string, parses the parameter value and passes it to the stylesheet before executing the transform.
Alternatively do it server-side, the same sort of process but you won't have to worry about the client's browser type.


--

Joe (Microsoft MVP - XML)
 
Old March 24th, 2006, 02:36 PM
Registered User
 
Join Date: Mar 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response. Please could you give me an example.

 
Old March 24th, 2006, 02:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Putting a parameter as part of a URL in a hyperlink doesn't have the effect of passing the parameter to the stylesheet. To pass a parameter to a stylesheet when running client-side (which you appear to be doing) you can't invoke the transformation using <?xml-stylesheet?>, you need to invoke it using the Javascript API from your HTML page, passing the parameter explicitly using the addParameter() method.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing MXML file as XML Parameter maulik33 Flex 0 January 9th, 2008 12:49 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
Passing Image File as a parameter MAKO C# 3 October 10th, 2006 12:55 PM
XSL Parameter xsl:param Harinath Chikoti XSLT 1 May 6th, 2005 03:15 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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