473,513 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with reading in a variable from xml-file

I have the following problem

XML-File:
<SEARCH>
<TAG>'x' or 'y'</TAG>
</SEARCH>

<CHARLIST>
<CHAR>a</CHAR>
<CHAR>x</CHAR>
<CHAR>f</CHAR>
<CHAR>z</CHAR>
<CHAR>r</CHAR>
<CHAR>y</CHAR>
<CHAR>u</CHAR>
</CHARLIST>

Stylesheet:
this works:
<xsl:variable name="var" select="'x' or 'y'"/>
<xsl:for-each select="//CHARLIST[CHAR=$var]">
<xsl:value-of select="$var"/>
</xsl:for-each>
=> output= x y

this doesn't work -> why? what can I do that this works too?:
<xsl:variable name="var" select="//SEARCH/TAG"/>
<xsl:for-each select="//CHARLIST[CHAR=$var]">
<xsl:value-of select="$var"/>
</xsl:for-each>
=> no output
Jul 20 '05 #1
1 3188
Hi Dennis,

Your first variable...

<xsl:variable name="var" select="'x' or 'y'"/>

The variable $var now contains a boolean value of true - because a string
(e.g. 'x') if evaluated as a boolean always evaluates to true. So the OR of
two true's is going to be true. And hence the use of that variable in a
predicate like...
//CHARLIST[CHAR=$var]
is synonymous with...
//CHARLIST[CHAR]
i.e. select all CHARLIST elements that have a child of CHAR

In the second variable...

<xsl:variable name="var" select="//SEARCH/TAG"/>

The variable $var now contains a node - and that node has a value of "'x' or
'y'". So now when you do...

<xsl:for-each select="//CHARLIST[CHAR=$var]">

you are looking for a CHARLIST element which has a child CHAR element that
has a value of "'x' or 'y'".

It seems you are trying to macro evaluate some string that contains "'x' or
'y'" - sorry, this cannot be done in XSLT/XPath.

But you could try something like...

== XML ====================================
<?xml version="1.0"?>
<root>
<SEARCH>
<TAG>|x|y|</TAG>
</SEARCH>
<CHARLIST>
<CHAR>a</CHAR>
<CHAR>x</CHAR>
<CHAR>f</CHAR>
<CHAR>z</CHAR>
<CHAR>r</CHAR>
<CHAR>y</CHAR>
<CHAR>u</CHAR>
</CHARLIST>
</root>
== end of XML =============================

NB. where the '|' character used is just a delimiter between the possible
values list.

== XSL ====================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="var" select="root/SEARCH/TAG"/>
<output>
<xsl:for-each
select="root/CHARLIST/CHAR[contains($var,concat('|',.,'|'))]">
<xsl:copy-of select="."/>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
== end of XSL =============================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Dennis Westermann" <we***************@spe-siemens.de> wrote in message
news:be**********@news.mch.sbs.de...
I have the following problem

XML-File:
<SEARCH>
<TAG>'x' or 'y'</TAG>
</SEARCH>

<CHARLIST>
<CHAR>a</CHAR>
<CHAR>x</CHAR>
<CHAR>f</CHAR>
<CHAR>z</CHAR>
<CHAR>r</CHAR>
<CHAR>y</CHAR>
<CHAR>u</CHAR>
</CHARLIST>

Stylesheet:
this works:
<xsl:variable name="var" select="'x' or 'y'"/>
<xsl:for-each select="//CHARLIST[CHAR=$var]">
<xsl:value-of select="$var"/>
</xsl:for-each>
=> output= x y

this doesn't work -> why? what can I do that this works too?:
<xsl:variable name="var" select="//SEARCH/TAG"/>
<xsl:for-each select="//CHARLIST[CHAR=$var]">
<xsl:value-of select="$var"/>
</xsl:for-each>
=> no output

Jul 20 '05 #2

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

Similar topics

2
3016
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
1
2748
by: Boris Wilhelms | last post by:
Hello all, at first, sorry for my bad English, I’ll give my best  We have a strange problem reading Text- and VarChar-Fields. Our configuration: -Windows 2003 Server -MySQL Server 3.23.36...
2
1368
by: Sean | last post by:
hi, I have a xml file. And i want to be able to read those values into a stored procedure. The XML structure is <cash> <tag section=1 id=1 param=2 param3=3 />
4
2407
by: Serban | last post by:
Hi I have two applications(client and server) that pass an XML document but I have a hard time reading the XML document on the server side. So the client application creates the XML document...
1
3601
by: Brad | last post by:
I'm having a problem reading a resource stream using the following syntax: Dim resStream As System.IO.TextReader = New _ ...
0
1241
by: Manfred Braun | last post by:
Hi All, I have a problem reading queue-messages async. My QueueReader has a Start() and a Stop() method and if my app starts, it calls Start(). The problem is, that there are possibly several...
28
2151
by: Andrew Poulos | last post by:
When loading an rss feed into Windows IE, doc.childNodes.length always equals 0. If I manually delete the <!DOCTYPE tag doc.childNodes.length is correct. I'm using doc = new...
4
3172
by: andreas.fabri | last post by:
I have a problem reading integers separated by commas with VC8 This program: ___________________________ // read.C #include <iostream> int main()
8
2363
by: Thirsty Traveler | last post by:
I have a dataset that is returned from a sql server select that contains metadata and a cached dataset saved in an xml column. I would like to recover the dataset for use in generating a crystal...
1
1524
by: Terry Olsen | last post by:
I download xml logs from several servers every day and read the data out of them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't...
0
7260
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,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
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...
0
4746
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...
0
3233
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...
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.