Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Variable scope

Reply
Thread Tools

Variable scope

 
 
John
Guest
Posts: n/a
 
      03-08-2005
I'm new to XSLT and I've been trying to figure out a solution for the
last couple of days. The XML & XSLT stylesheet are below. Basically I
want to declare some language (English, French, etc.) variables at the
beginning of the stylesheet, however I keep getting variable scope errors.

The language strings are specific to this template. There aren't many
since most of the data is coming from an application through XML. Below
is a simplified example. I'm trying to accomodate multiple languages
without having to maintain multiple stylesheets. Any ideas on how to
accomplish this?

XML:
----
<root>
<language>en</language>
</root>

XSL:
----
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html" encoding="UTF-8" indent="yes" />

<xsl:if test="//language = 'en'">
<xsl:variable name="language">English</xsl:variable>
</xsl:if>

<xsl:if test="//language = 'fr'">
<xsl:variable name="language">French</xsl:variable>
</xsl:if>

<xsl:template match="/">
<xsl:value-of select="$language" /> <== variable 'language' not found
</xsl:template>

</xsl:stylesheet>

Thanks!
 
Reply With Quote
 
 
 
 
Ben Edgington
Guest
Posts: n/a
 
      03-08-2005
John <(E-Mail Removed)> writes:

> XSL:
> ----
> <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xslutput method="html" encoding="UTF-8" indent="yes" />
>
> <xsl:if test="//language = 'en'">
> <xsl:variable name="language">English</xsl:variable>
> </xsl:if>
>
> <xsl:if test="//language = 'fr'">
> <xsl:variable name="language">French</xsl:variable>
> </xsl:if>
>
> <xsl:template match="/">
> <xsl:value-of select="$language" /> <== variable 'language' not found
> </xsl:template>
>
> </xsl:stylesheet>


Try this:

<xsl:variable name="language">
<xsl:if test="//language = 'en'">English</xsl:if>
<xsl:if test="//language = 'fr'">French</xsl:if>
</xsl:variable>

The XSL way of doing things takes a little bit of getting
your head round, but you'll soon get the hang of it.

Regards,

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      03-08-2005
Ben Edgington wrote:
> Try this:
>
> <xsl:variable name="language">
> <xsl:if test="//language = 'en'">English</xsl:if>
> <xsl:if test="//language = 'fr'">French</xsl:if>
> </xsl:variable>


or use xsl:choose, xsl:when, xsltherwise.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments