XSLT: Global Parameters

Stefan Schmitz

Usenet Archive
Joined
Feb 9, 2005
Messages
1
Reaction score
0
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
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
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.
 

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
548,049
Messages
3,104,244
Members
248,133
Latest member
DujonT

Latest Threads

Top