Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2009, 11:48 AM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to ignore cases on attribute value

Hi. I'm using XSLT 1.0.

I have the following 3 possible inputs:
<Ball Color='yellow'>big</Ball>
<Ball Color='Yellow'>Small</Ball>
<Ball Color='YELLOW'>MEDIUM</Ball>

How do I get the value based on the Color "yellow" attribute by ignoring the "yellow" cases (lower, mix, upper)?

This is what I have so far:
<xsl:template match="Ball">
<xsl:value-of select='normalize-space(@Color='yellow')'/>
</xsl:template>

My current output is only "big",
when it should be "big", "Small", and "MEDIUM".

I tried using this but didn't work:
normalize-space(@Color=translate('yellow', 'abcd...z', 'ABCD...Z'))
 
Old January 30th, 2009, 11:55 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 1.0 you need to use the translate function e.g.
Code:
<xsl:variable name="lc" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="Ball">
  <xsl:value-of select="translate(normalize-space(@Color), $uc, $lc) = 'yellow'"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 30th, 2009, 12:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Translating the constant string 'yellow' into upper case isn't going to do much good, you know what the answer is so you might as well write 'YELLOW'. It's the attribute @Color that you need to translate.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get attribute by ignoring the cases (case-insensitive) 2BOrNot2B XSLT 1 January 27th, 2009 06:36 PM
how to create buisness USE CASES via ASP khalid08 Classic ASP Databases 0 April 4th, 2006 07:34 PM
test cases for data submission simplyAns MySQL 2 November 2nd, 2005 10:21 AM
unable to use junit test cases for web project in deb_net J2EE 0 October 24th, 2005 12:54 AM
Ignore this post...its crap! clandestine XML 4 May 31st, 2005 06:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.