Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old December 16th, 2005, 08:37 AM
Registered User
 
Join Date: Dec 2005
Location: Kirkcaldy, Fife, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Url Variables

Im having difficulty passing a variable through a URL so that an xsl page can read it. The setup I have is basically a coldfusion page which reads in the xml page and the xsl page and combines them. This page is called sport.cfm. This is also the page that the url parameter is passed to. ie sport.cfm?sportid=1

I need to access that id in the xsl page so that by using the xsl code I can select the correct part of the xml page.

My basic problem is getting the xsl page to recognise the url variable. Once I can access that I can do the rest.
  #2 (permalink)  
Old December 16th, 2005, 09:07 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't supplied much detail.

Extract the query parameters in the calling application, and supply the values as parameters to the stylesheet using global <xsl:param> declarations.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old December 16th, 2005, 11:31 AM
Registered User
 
Join Date: Dec 2005
Location: Kirkcaldy, Fife, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah right so extract it in the coldfusion page which calls the xml and xsl pages? I have tried this and it doesnt work.

Below is the coldfusion page.

sport.cfm?id=1

<cfset sportid = #url.id#>
<cfset MyXmlFile = Expandpath("olympics.xml")>
<cffile action="READ" variable="xmlInput" file="#MyXmlFile#">
<cfset MyXmlFile = Expandpath("b.xsl")>
<cffile action="READ" variable="xslInput" file="#MyXmlFile#">
<cfset xmlOutput = XMLTransform(xmlInput, xslInput)>

<cfcontent type="text/plain" reset="yes">
<cfoutput>#xmloutput#</cfoutput>

The xsl is below.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' omit-xml-declaration="yes" />
<xsl:param name="sportid" />

  <html>
  <head>
            <title>Events Page</title>
        </head>
  <body>
    <xsl:apply-templates select="events/category[categoryid=$sportid]" />
     <xsl:value-of select="$sportid"></xsl:value-of>
    </body>
  </html>
</xsl:template>


<xsl:template match="category">
   <xsl:value-of select="text()" /> <br/>
   <xsl:value-of select="categoryinfo/p/text()" /> <br/>
   <xsl:apply-templates select="event" />
</xsl:template>

<xsl:template match="event">
  <a href="event.cfm?id={eventid}"> <xsl:value-of select="eventname/text()" /></a> <br/>
</xsl:template>



</xsl:stylesheet>


  #4 (permalink)  
Old December 16th, 2005, 12:13 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know anything about ColdFusion, I'm afraid. I would be surprised if just doing

<cfset sportid = #url.id#>

is enough to set a value for the sportid parameter in your stylesheet: I would have thought it just sets a local variable in ColdFusion.

(Why did they choose this weird pseudo-XML syntax?)

Look in the ColdFusion transformation API for an instruction to set stylesheet parameters.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #5 (permalink)  
Old December 20th, 2005, 04:38 PM
Registered User
 
Join Date: Dec 2005
Location: , NY, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is a little brute force but I believe you can solve your problem by using the ColdFusion replace function on the xslInput variable after you read it in.
Replace(string, substring1, substring2 [, scope ])

If you change the following - changes in bold:

<cffile action="READ" variable="xslInputtemp" file="#MyXmlFile#">
<cfset xslInput = Replace(xslInput,"$sportid",URL.id,"ALL")<cfset xmlOutput = XMLTransform(xmlInput, xslInput)>

That should alter your XSL and replaces any instance of $sportid with the value of URL.id.

Good Luck,
Tom

  #6 (permalink)  
Old December 21st, 2005, 10:33 AM
Registered User
 
Join Date: Dec 2005
Location: Kirkcaldy, Fife, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much that did the trick.




Similar Threads
Thread Thread Starter Forum Replies Last Post
URL rewriting with URL forwarding mtabyana BOOK: Professional Search Engine Optimization with PHP: A Dev's Guide to SEO ISBN: 978-0-470-10092-9 0 October 22nd, 2007 08:22 AM
URL variables in XSL Pinguin89 XSLT 1 March 16th, 2006 10:57 AM
Sending URL with variables cckiat General .NET 4 December 7th, 2004 06:08 AM
extract URL from Favorites (.URL Files) PhilHawks VB.NET 2002/2003 Basics 2 November 2nd, 2004 04:35 AM
CH:2 Passing Variables throught a URL. GraphicArmy BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 5 April 28th, 2004 02:36 AM





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