473,323 Members | 1,537 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,323 software developers and data experts.

Choosing right element

Hi. I have a dilemma. Here is my xml.

<time>
<hour>1</hour>
<minute>0</minute>
</time>

<time timezone="PST">
<hour>1</hour>
<minute>15</hour>
</time>

<time timezone="EST">
<hour>2</hour>
<minute>20</minute>
</time>

<time timezone="TOK">
<hour>15</hour>
<minute>45</minute>
</time>

I want to choose only one of these <timedepending on system timezone
(variable $tz). If there is no system time defined, then it would
choose the first element with no timezone. Here is my xslt, but its
not working correctly.

<xsl:choose>
<xsl:when test="@timezone=$tz">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>

May 7 '07 #1
1 1482
<xsl:choose>
<xsl:when test="@timezone=$tz">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
What you've said is "If the current node's timezone attribute has the
desired value, output the node's value. If it doesn't, then still output
the node's value." Not what you wanted. Especially since value-of won't
do what you want either; it will output the concatenated text content,
which will be something like
1
15
with line breaks before and after, and with the indentation.
What you wanted was "If there is a <timeelement which has the right
timezone output it, otherwise output the one with no timezone". You
didn't show us the context, but assuming that you're starting from the
parent of the <timeelements one way to write this would be:

<xsl:choose>
<xsl:when test="time[@timezone=$tz]">
<xsl:apply-templates select="time[@timezone=$tz]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="time[@timezone='']"/>
</xsl:otherwise>
</xsl:choose>

Note that here I'm also assuming you want to apply a template to the
<timeelements in order to format their content a bit more usefully.

Hope that helps.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 7 '07 #2

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

Similar topics

0
by: Carsten Gehling | last post by:
> -----Oprindelig meddelelse----- > Fra: python-list-admin@python.org > På vegne af David McNab > Sendt: 17. juli 2003 01:32 > Til: python-list@python.org > Emne: Re: Choosing the right...
11
by: Jean de Largentaye | last post by:
Hi, I need to parse a subset of C (a header file), and generate some unit tests for the functions listed in it. I thus need to parse the code, then rewrite function calls with wrong parameters....
1
by: will | last post by:
why doesnt this work? Im basically trying to get the value of the root node attribute the 'Result' attr. Which can be one of 3 things. OK, ERROR or INVALID, and then choosing between the 3 and...
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
4
by: Madi | last post by:
Dear all, Im in a confusion about choosing a job offer.Right now im working in ..Net 3.0 components(Workflows,WCF),asp.net 2.0 webparts and all.Im having a good exposure here but with a very...
19
by: hansBKK | last post by:
Upfront disclaimer - I am a relative newbie, just starting out learning about PHP, mostly by researching, installing and playing with different scripts. I am looking for a host that will provide...
2
by: anitawa | last post by:
Hi, Im in a dilemma and need some help. I have an xml like this: <animal species="dog"> <color>brown</color> </animal> <animal species="cat"> <color>black</color>
14
by: Leah | last post by:
I am a student and are required to build a website that provide services (client-server). I need advice in choosing approach or to be exact the methodology that appropriate for such development....
7
by: tonyaim83 | last post by:
Hi... My input file is as follows :- A<-B<-C<-D A<-C<-E<-F<-P ....... ..... What i want is to first store the given input as follows :- {{{A,B},{B,C},{C,D}},{{A,C},{C,E},{E,F},{F,P}}} and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.