473,799 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xslt question: using variable in xpath not allowed?

We have preffered language set as variable in xslt:

<xsl:variable name="preferred _language">
zh
</xsl:variable>

Data:
<name xml:lang="de">R aw Materials (Mining incl.)</name>
<name xml:lang="zh"> 材料(包 采矿业) </name>

This works:
<h2><xsl:valu e-of select="name[@xml:lang='zh']"/></h2>

This will not work (produce result looks like "<h2></h2>"):
<h2><xsl:valu e-of select="name[@xml:lang=$pref erred_language]"/></h2>

For me it's no problem if I have to use <chooseand <whento do the same
task (for each <name>, output <h2>xx</h2only if the xml:lang equal to
$preferred_lang uage). Just I wish to confirm that is it "in all places
variable cannot be used in xpath" or "I have used xpath with variable in
wrong format".

another question: is it possible to use URI parameter in xslt? I am
developing in php so I can write:

<xsl:variable name="preferred _language">
<?= $_GET['lang'] ?>
</xsl:variable>

but I am stupid to do this if XSLT itself can use URI parameter. By URI
parameter I mean the "?lang=zh" section in following URI:
http://www.mysite.com/businessCategory.xml?lang=zh
Oct 22 '06 #1
2 2099

??? wrote:
We have preffered language set as variable in xslt:

<xsl:variable name="preferred _language">
zh
</xsl:variable>

Data:
<name xml:lang="de">R aw Materials (Mining
incl.)</name>
<name xml:lang="zh">? ??(?????) </name>

This works:
<h2><xsl:valu e-of
select="name[@xml:lang='zh']"/></h2>

This will not work (produce result looks like
"<h2></h2>"):
<h2><xsl:valu e-of
select="name[@xml:lang=$pref erred_language]"/></h2>
The usual advice: if you want people to help you, make it
easier for them. Post something people can feed to their
XSLT processors without going through the motions of
writing all the usual <xsl:stylesheet >s, <xsl:template >s
etc.

Your problem is that $preferred_lang uage!='zh'. Instead, it
contains 'zh' and a lot of useless whitespace.

<xsl:value-of
select="name[contains($prefe rred_language,@ xml:lang)]"/>

It's ugly, but it works. Also, see below.
another question: is it possible to use URI parameter in
xslt? I am developing in php so I can write:

<xsl:variable name="preferred _language">
<?= $_GET['lang'] ?>
</xsl:variable>
Don't do that. That's what created your problem in the
first place. If you would've passed a parameter to your
stylesheet instead of tinkering with the *source*, you
wouldn't have needed any advice. What you should use to
pass parameters depends on whether you're using PHP4+XSLT
or PHP5+XSL. In either case, it's all in the docs on

http://php.net/

A temporary solution:

<xsl:variable name="preferred _language"><?=
$_GET['lang'] ?></xsl:variable>
but I am stupid to do this if XSLT itself can use URI
parameter. By URI parameter I mean the "?lang=zh" section
in following URI:
http://www.mysite.com/businessCategory.xml?lang=zh
Oh, I see now. You're using client-side transformations .
It'd be better to leave that to the server, especially
since it's easy to do in PHP.

--
roy axenov

Oct 22 '06 #2
*韡* wrote:
We have preffered language set as variable in xslt:

<xsl:variable name="preferred _language">
zh
</xsl:variable>
Better make that e.g.
<xsl:variable name="preferred _language" select="'zh'"/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 22 '06 #3

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

Similar topics

1
2754
by: Johannes Lebek | last post by:
Hi there, somehow, I cannot access nodes that are stored in a variable. I'm using Xalan 2.5.1 and the following commands: ================ BEGIN ==================== <xsl:variable name="referenced-node" select="//a"/> <xsl:variable name="attribute-source">
6
2934
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
3
2143
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color> <color>green</color> </xsl:variable>
5
9553
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case where node ordering matters, and also the case where it doesn't, but perhaps that is an advanced topic). Ideally the method should be available to xpath expressions, so I think that creating new templates which compare nodes will not work (well,...
4
21210
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
3
3095
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION> <OPTION>3<OPTION> </FIELD>
10
6049
by: Bilal | last post by:
Hello, I'm trying to perform some string manipulations in my stylesheet and have gotten stuck on the issue below so hopefully can elicit some useful hints. Namely, the problem is that I need to convert an unqualified Xpath to a fully qualified Xpath in an identity transform, i.e. /AAA/BBB/CCC/@DDD
15
2163
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and displaying others as node 1 and node 2? This data is XML from a Barracuda Spam server that has grown to 2. Here is a snip from my form draw. Imports System Imports System.IO Imports System.Net
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.