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 December 21st, 2006, 01:09 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change value based on other value

I have the following XML:

<Box>
  <Color>Fuchsia</Color>
  <Toy>Ball</Toy>
</Box>

If <Color> is "Fuchsia", I like to change the value of <Toy> to be "Pink Ball". The <Color> tag is then deleted.

Or if <Color> is "Lavender", I like to change the value of <Toy> to be "Purple Ball". The <Color> tag is then deleted.

The new XML should be:

<Box>
   <Toy>Pink Ball</Toy>
</Box>

Here is my XSLT so far:

<xsl:template name="Box"/>
   <xsl:choose>
      <xsl:when test="contains(normalize-space(.), 'Fuchsia')">
           <xsl:copy-of select="Toy"/>
      </xsl:when>
      <xsl:when test="contains(normalize-space(.), 'Lavender')">
         <xsl:copy-of select="Toy"/>
      </xsl:when>
   </xsl:choose>
</xsl:template>

Please help.
 
Old December 21st, 2006, 02:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="Box[Color='Fuschia']">
  <Box><Toy>Pink Ball</Toy></Box>
</xsl:template>

<xsl:template match="Box[Color='Lavender']">
  <Box><Toy>Purple Ball</Toy></Box>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 21st, 2006, 03:35 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your quick response.

Sorry, I was not cleared in my previous message. I am looking for more into concatenation since I might not know the value of <Toy>. I'm looking for something like this.

 "Pink" + the value of <Toy>

If value of <Toy> is "Ball", then the result is "Pink Ball".
If value of <Toy> is "Block", then the result is "Pink Block".

Appreciate any helps.
 
Old December 21st, 2006, 08:19 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="Box[Color='Fuschia']">
  <Box><Toy>Pink <xsl:value-of select="Toy"/></Toy></Box>
</xsl:template>

I'm not sure why you're finding this so difficult - you probably need to do some more background reading about the language before you do any more coding.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
change masterpage based on the folder crab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 April 14th, 2008 09:32 AM
Change Sort-by attribute based on parent tclancy XSLT 2 March 24th, 2006 05:00 PM
Role based securty Warbird General .NET 2 August 17th, 2004 12:50 PM
change background color of cell based on value vurtman ASP.NET 1.0 and 1.1 Basics 4 February 26th, 2004 03:52 PM
Results based on Date hcweb Classic ASP Basics 1 August 12th, 2003 02:28 PM





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