|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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- |
|
#3
|
|||
|
|||
|
Thanks Miska! It worked like a charm. You saved me hours and hours of work trying to figure this out!
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Help with XML/XSLT Formula |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|