XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 3rd, 2004, 07:27 PM
MyDogCujo MyDogCujo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 MyDogCujo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking Help with XML/XSLT Formula

I am trying to come up with a formula for my XSLT Stylesheet that will return a result for the following:

If Column A is Equal to or Less than Column B, then = 0, but If Column A is Greater than Column B then calculate the difference (Column A - Column B).

I am completely lost! Any help would be greatly appreciated.

Reply With Quote
  #2  
Old October 4th, 2004, 05:38 AM
Miska's Avatar
Miska Miska is offline
Madden Maniac
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Finland
Posts: 519 Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level)Miska User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 3 h 47 m 50 sec
Reputation Power: 8
Here's a solution for you. If want to learn it yourself look at xsl:variable and xsl:choose from XSLT reference.

XML file I used:
Code:
 <?xml version="1.0" encoding="ISO-8859-1"?>
<calc>
<value1>2</value1>
<value2>1</value2>
</calc>

And the XSL transformer:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:template match="calc">
<html>
<body>
<xsl:variable name='test' select='value2 - value1'/> 
<p>The value is:
<xsl:choose>
<xsl:when test='$test = 0'>
0
</xsl:when>
<xsl:when test='$test < 0'>
0
</xsl:when>
<xsl:when test='$test > 0'>
<xsl:value-of select='$test' />
</xsl:when>
</xsl:choose>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Hope this helps, just remember to use < for smaller than instead of the normal '<' sign. Forum shows it as '<' even though it's really the escaped '<'...

-Miska-

Reply With Quote
  #3  
Old October 5th, 2004, 01:17 AM
MyDogCujo MyDogCujo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 MyDogCujo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Thanks Miska!

Thanks Miska! It worked like a charm. You saved me hours and hours of work trying to figure this out!


Quote:
Originally Posted by Miska
Here's a solution for you. If want to learn it yourself look at xsl:variable and xsl:choose from XSLT reference.

XML file I used:
Code:
 <?xml version="1.0" encoding="ISO-8859-1"?>
<calc>
<value1>2</value1>
<value2>1</value2>
</calc>

And the XSL transformer:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
<xsl:template match="calc">
<html>
<body>
<xsl:variable name='test' select='value2 - value1'/> 
<p>The value is:
<xsl:choose>
<xsl:when test='$test = 0'>
0
</xsl:when>
<xsl:when test='$test < 0'>
0
</xsl:when>
<xsl:when test='$test > 0'>
<xsl:value-of select='$test' />
</xsl:when>
</xsl:choose>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Hope this helps, just remember to use < for smaller than instead of the normal '<' sign. Forum shows it as '<' even though it's really the escaped '<'...

-Miska-

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Help with XML/XSLT Formula


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT