XSLT: Global Parameters

S

Stefan Schmitz

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:eek:utput 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
 
D

Dimitre Novatchev

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.
 
J

Joris Gillis

Tempore 11:24:21 said:
<xsl:text><xsl:value-of select="$Selection"/></xsl:text>
And do replace this invalid line with:
<xsl:value-of select="$Selection"/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top