473,405 Members | 2,282 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,405 software developers and data experts.

How do I write a string in the destination element depending on what the string is in the source, using XSLT/XPath? (Like a switch statement.)

Is there something like a switch statement in XPath? What I want to do is
this:

In the source there is an element called "member" with either the value "0"
or "1". In the destination element (also called "member") the value should
be "No" or "Yes" (Where "0" corresponds to "No" and "1" to "Yes"). How do I
do this?
Nov 12 '05 #1
1 2366
Joakim Olesen wrote:
Is there something like a switch statement in XPath? What I want to do is
this:

In the source there is an element called "member" with either the value "0"
or "1". In the destination element (also called "member") the value should
be "No" or "Yes" (Where "0" corresponds to "No" and "1" to "Yes"). How do I
do this?


Usual way:

<xsl:choose>
<xsl:when test="member = 0">No</xsl:when>
<xsl:when test="member = 1">Yes</xsl:when>
</xsl:choose>

Tricky way:

<xsl:value-of select="concat(
substring('No', (member=1)*string-length('No')+1),
substring('Yes', (member=0)*string-length('Yes')+1)
)"/>

Cool way:

<xsl:value-of select="msxsl:node-set('No')[current()/member=0]) |
msxsl:node-set('Yes')[current()/member=1])"/>

Lookup table way (better when you have lots of options):

<xsl:stylesheet xmlns:foo="bar"...>
<foo:table>
<item from="0" to="No"/>
<item from="1" to="Yes"/>
</foo:table>

....
<xsl:value-of
select="document('')/foo:table/item[@from=current()/member]/@to"/>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
8
by: Wolfgang Lipp | last post by:
<annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with the consent of their authors. -- _w.lipp </annotation> From:...
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
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...
1
by: Yuriy | last post by:
Hi, Can anybody explain the following? Say I have the following source XML and XSLT (see below). No matter what this XSLT does. It is just a sample to show a problem. the idea is that XSLT...
4
by: Jethro | last post by:
I've tried to find the simplest demonstration of my issue. I have source XML that looks like this (not a real XSD schema, but it doesn't matter at this point): (in var xmlStr:) <xsd:element...
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...
1
by: Ronald S. Cook | last post by:
I have a string (see below) that I want to parse out the values. As you can see, some are element-based and some are attribute-based. <METADATA version="Format5"><TITLE value="Adrenaline...
1
by: Riaan | last post by:
As the subject suggests, I am trying to populate a element (of type xs:string) with a entire XML structure from the source. The problem is, I get the transformation to work... but the tranformation...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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
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,...
0
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...

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.