• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use xsl:when

 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I use xsl:choose, xsl:when and xsl therwise? This is what I am trying to do - I have an element -

I have an XSL which displays this in a table, which is working fine. Now I want to show all males in one color and females in another. How can I speify condition for this in xsl:when. I tried sth, but it displayed all in one color.
Also, in DTD I have specified default value for gender as "female", so not all <person> elements will have gender attribute in them.
Can somebody help?
TIA,
- Manish
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manish,
Give this a try:

I believe that should be the trick.
HTH,
/rick
Darn smilies...... :P
[ May 21, 2002: Message edited by: Rick Salsa ]
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rick! I'll give it a try.
Also, this is what I tried without using the xsl variable; but didn't work out. Can somebody point out what am I missing? I want to get this working...

I have just started experimenting with XML, and not very comfortable with XPATH expressions, where can I find more information abt it?
TIA,
- Manish
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's working; finally.
The xml:when test should have been -> test=".[person/@gender='female']" , however the previous test that I mentioned is always returning true. I wonder why? Can someone explain?
TIA,
- Manish
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Your test translates to:
Is there any element in the tree that has a child element named 'person' that has an attribute named 'gender' with value 'female' ?
Which is true of course as long as there aren't
just males.
With // you are selecting all elements in tree.
This nodeset is then filtered with the predicate [person/@gender=female] which is evaluated relative to any node of the nodeset.
The filtered nodeset is then evaluated as boolean
for the test, which means the test is only false
when the nodeset is empty.
 
reply
    Bookmark Topic Watch Topic
  • New Topic