473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

XSLT: Global Parameters

I have a problem using a global parameter to control the
XSL-Transformation of my XML-Document.

My XML-Document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Football xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="d:\_Privat\Football \XML\Football.xsd">
<Season>
<Opponents>
<Opponent ID="ID1001" Town="Duesseldorf"/>
</Opponents>
</Season>
<Football>

And my XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="html" encoding="UTF-8" indent="no"/>

<xsl:param name="Selection" select="Try"/>

<xsl:template match="Football">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>

<xsl:template match="Season">
<head>
<title>
<xsl:text>Saison </xsl:text>
<xsl:value-of select="@Year"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="$Selection"/>
<xsl:text>)</xsl:text>
</title>
</head>
<body>
<center>
<xsl:text><xsl:value-of select="$Selection"/></xsl:text>
</center>
</body>
</xsl:template>

If I transform the XML-Document with this stylesheet the
value-of($Selection)-Part is in both cases empty. If I change the
select-Value to 1 or 12 (Number) or add this to the
Xalan-Transformator (-p Selection 1) as a parameter the given value
appears. But I can't understand why this only works with numbers? What
am I doing wrong?

Thanks
Stefan
Jul 20 '05 #1
2 3064
The problem is here:
<xsl:param name="Selection" select="Try"/>
This will select the node-set of all children with name "Try" of the current
node (the document node "/") -- that is either the top element of the xml
document is named "Try" in which case it will be selected, or the XPath
expression "Try" will select nothing -- and this is exactly your
case as the top element is named "Football".

The solution is to use:

<xsl:param name="Selection" select="'Try'"/>

that is, enclose Try in inner apostrophes. Then it is interpreted as a
string literal and not as a name that is part of a location step of an XPath
expression.
Hope this helped.
Cheers,

Dimitre Novatchev.


"Stefan Schmitz" <Ca**********@gmx.de> wrote in message
news:b0*************************@posting.google.co m...I have a problem using a global parameter to control the
XSL-Transformation of my XML-Document.

My XML-Document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Football xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="d:\_Privat\Football \XML\Football.xsd">
<Season>
<Opponents>
<Opponent ID="ID1001" Town="Duesseldorf"/>
</Opponents>
</Season>
<Football>

And my XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="html" encoding="UTF-8" indent="no"/>

<xsl:param name="Selection" select="Try"/>

<xsl:template match="Football">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>

<xsl:template match="Season">
<head>
<title>
<xsl:text>Saison </xsl:text>
<xsl:value-of select="@Year"/>
<xsl:text> (</xsl:text>
<xsl:value-of select="$Selection"/>
<xsl:text>)</xsl:text>
</title>
</head>
<body>
<center>
<xsl:text><xsl:value-of select="$Selection"/></xsl:text>
</center>
</body>
</xsl:template>

If I transform the XML-Document with this stylesheet the
value-of($Selection)-Part is in both cases empty. If I change the
select-Value to 1 or 12 (Number) or add this to the
Xalan-Transformator (-p Selection 1) as a parameter the given value
appears. But I can't understand why this only works with numbers? What
am I doing wrong?

Thanks
Stefan

Jul 20 '05 #2
Tempore 11:24:21, die Wednesday 09 February 2005 AD, hinc in foro {comp.text.xml} scripsit Stefan Schmitz <Ca**********@gmx.de>:
<xsl:text><xsl:value-of select="$Selection"/></xsl:text>

And do replace this invalid line with:
<xsl:value-of select="$Selection"/>

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Fiat W3C in tenebris
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Geathaa | last post by:
Hi everyone, I want to transform a xml document containing the description of a menu tree to HTML. The MenuTree XML contains the target URL for each tree node. Some URL's contain parameters...
1
by: David Way | last post by:
I have an xml file looks like this: <root> <L1>a</L1> <L2>b <L3>c</L3> </L2> </root> In my xslt file, I do a template match to get to <L3>
2
by: philips | last post by:
Hi everybody, I am using the Xalan 1.8 C++ API in a real-time financial application which need to apply XSLT transformations on XML input messages received on-the- fly. On the process output,...
4
by: Thomas Mann | last post by:
Hi, how can I make my XSLT-stylesheet insert a timestamp (date/time) into the output file ? Regards Thomas
1
by: Michael | last post by:
I am having a problem with scoping of parameters in my XSLT Stylesheet...here is the stylesheet (the xml document is irrelevant for the example) <?xml version="1.0" encoding="UTF-8"?>...
12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
2
by: Richard L Rosenheim | last post by:
Is it possible to include addition tags in a XSLT file, that the XSLT processor will, for all practical purposes, ignore? What I'm looking to do is to include a section to contain information...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
2
by: Efi Merdler | last post by:
Hello, As I understand it is impossible in xslt to change the value of a variable after you assigned a value to it. I would like to simulate a flag. For example if something happens in template...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.