473,378 Members | 1,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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">Raw Materials (Mining incl.)</name>
<name xml:lang="zh">原材料(包括采矿业) </name>

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

This will not work (produce result looks like "<h2></h2>"):
<h2><xsl:value-of select="name[@xml:lang=$preferred_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_language). 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 2071

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

<xsl:variable name="preferred_language">
zh
</xsl:variable>

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

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

This will not work (produce result looks like
"<h2></h2>"):
<h2><xsl:value-of
select="name[@xml:lang=$preferred_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_language!='zh'. Instead, it
contains 'zh' and a lot of useless whitespace.

<xsl:value-of
select="name[contains($preferred_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
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...
6
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...
3
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>...
5
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...
4
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...
3
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>...
10
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...
15
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.