XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ed ButcherSubject: Trouble with param
Author: Ed Butcher
Date: 12 Mar 2007 11:27 AM
Hi

I'm trying to use a parameter to select one recipe from a file containing several hundred recipes. The XML looks like this:

<recipe sLove="loveeveryday" name="BLT Special">
<sTitle>BLT Special</sTitle>
<sLove>loveeveryday</sLove>
<sImage>BLT Special</sImage>
<sSubTitle>Makes 2 sandwiches</sSubTitle>
<ingredients>
<ingredient>4 slices soft white bread</ingredient>
<ingredient>4 rashers smoked, rindless back bacon</ingredient>
<ingredient>2 pork and herb sausages</ingredient>
<ingredient>Butter, softened (or favourite spread)</ingredient>
<ingredient>2 crisp lettuce leaves, shredded</ingredient>
<ingredient>3 small vine tomatoes, sliced</ingredient>
<ingredient>2 tbsp mayonnaise or tomato relish</ingredient>
</ingredients>
<methods>
<method>1. Cook the bacon and sausages under a pre-heated grill, turning, until cooked. Slice the sausages diagonally.</method>
<method>2. Spread the slices of bread with butter.Arrange the lettuce and tomato slices on two slices of bread. Top with sausage slices, mayonnaise or tomato relish and bacon.</method>
<method>3. Place the remaining bread slices on top, cut in half and serve immediately.</method>
</methods>
</recipe>

The problem I'm having is trying to filter out just one recipe. I'm calling the page like this: recipes.asp?recipetitle=BLT Special

The XSL I thought should work is...

<xsl:param name="recipetitle"/>
<xsl:template match="/">

<xsl:for-each select="recipes/recipe[sTitle='{recipetitle}']">

<h1><xsl:value-of select="sTitle"/></h1>
<h3><xsl:value-of select="sSubTitle"/></h3>

<xsl:for-each select="ingredients">
<h3>Ingredients</h3>
<ul>
<xsl:apply-templates select="ingredient"/>
</ul>
</xsl:for-each>

<xsl:for-each select="methods">
<h3>Method</h3>
<ul>
<xsl:apply-templates select="method"/>
</ul>
</xsl:for-each>

<xsl:for-each select="topTips">
<h3>Top Tips</h3>
<xsl:apply-templates select="tip"/>
</xsl:for-each>


</xsl:for-each>

This works fine if I test it, replacing the first for-each with
<xsl:for-each select="recipes/recipe/[sTitle='BLT Special']">

Any ideas?

Thanks
Ed


Postnext
Ivan PedruzziSubject: Trouble with param
Author: Ivan Pedruzzi
Date: 12 Mar 2007 11:34 AM

use $ to reference variables and parameters

<xsl:for-each select="recipes/recipe[sTitle=$recipetitle]">


Ivan Pedruzzi
Stylus Studio Team

Postnext
Ed ButcherSubject: Trouble with param
Author: Ed Butcher
Date: 12 Mar 2007 11:42 AM
Thanks - I've tried that, and I'm still not getting any results.

Is there an easy way to test the value of the parameter I'm passing to to the XSL file?

Postnext
Ivan PedruzziSubject: Trouble with param
Author: Ivan Pedruzzi
Date: 12 Mar 2007 03:18 PM
Could you please show the code that runs XSLT from ASP?

Are you binding the ASP parameters to the Transformer object?

Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

Postnext
Ed ButcherSubject: Trouble with param
Author: Ed Butcher
Date: 14 Mar 2007 10:49 AM
I've changed the way I was approaching this: now I'm using SelectSingleNode in my ASP.

This is what I have...

<%
Dim xmlSource, xslSource, strOutput, recipetitle, objNode

recipetitle = Request.QueryString("recipetitle")

Set xmlSource=Server.CreateObject("Microsoft.XMLDOM")
Set xslSource=Server.CreateObject("Microsoft.XMLDOM")
xmlSource.async=false
xslSource.async=false

xmlSource.load(Server.MapPath("../../objects/xml/template_recipes_new.xml"))
xslSource.load(Server.MapPath("../../objects/xsl/everyday_recipes_listing.xsl"))

if xmlSource.parseError.errorcode<>0 then
response.write xmlSource.parseError.errorcode
else
Set objNode = xmlSource.SelectSingleNode("recipes/recipe[@name='" & recipetitle & "']")

response.write "<h1>" & recipetitle & "</h1>"

strOutput = (objNode.transformNode(xslSource))
strOutput = replace(strOutput, "&lt;br&gt;&lt;br&gt;", "</p><p>")

Response.Write strOutput
end if

set xmlSource = nothing
set xslSource = nothing
set objNode = nothing
%>

This is correctly displaying the right bit of the XML file, although my XSL isn't working properly - it's not displaying all the elements I expect it to.

Posttop
Ivan PedruzziSubject: Trouble with param
Author: Ivan Pedruzzi
Date: 14 Mar 2007 02:35 PM

The ASP code is not binding the XSLT parameter "recipetitle"

Please visit this link for a complete example
http://msdn2.microsoft.com/en-us/library/ms767547.aspx

Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.