XSLT: Global Parameters

Discussion in 'XML' started by Stefan Schmitz, Feb 9, 2005.

  1. 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
     
    Stefan Schmitz, Feb 9, 2005
    #1
    1. Advertising

  2. Re: Global Parameters

    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" <> wrote in message
    news:...
    >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, Feb 9, 2005
    #2
    1. Advertising

  3. Stefan Schmitz

    Joris Gillis Guest

    Tempore 11:24:21, die Wednesday 09 February 2005 AD, hinc in foro {comp.text.xml} scripsit Stefan Schmitz <>:

    > <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-view.cgi?userid=38041)
    Fiat W3C in tenebris
     
    Joris Gillis, Feb 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    700
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,696
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    630
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    727
    Henry S. Thompson
    Oct 19, 2005
  5. OK
    Replies:
    5
    Views:
    625
    Peter Bromberg [C# MVP]
    Nov 26, 2007
Loading...

Share This Page