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 November 3rd, 2013, 06:58 PM
Authorized User
 
Join Date: Jun 2013
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
Angry How do I extract a single value representing greatest absolute value?

Hi All and MANY thanks for all the valuable help I and others receive from this forum. I'm using Win7, 64bit and xsl 1.0, as all MS FlightSim Users are locked in to 1.0.
Here's my xml, which I'm sure you've seen b4:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='MissionProfile.xsl'?>
<MissionProfile>
<Profile name="BHP" value="290000"/>
<Profile name="EOT" value="356.51129"/>
<Profile name="Cnt" value="0"/>
<Profile name="Fire" value="0"/>
<Profile name="SIMVAR_VERSION" value="V1.0.3537.0"/>
<Profile name="PROFILEPATH" value="c:\program files (x86)\microsoft games\microsoft flight simulator x\missions\Backcountry\USAMSL2RP2\Elko2Reno_profil e.xml"/>
<Gather>
<Stat ID="" Name="GPS WP CROSS TRK" Unit="decimile">
<Point Time="491347723">-0.67273</Point>
<Point Time="491347783">-0.83152</Point>
<Point Time="491347843">-2.00702</Point>
<Point Time="491347903">-2.66593</Point>
<Point Time="491347963">-2.71417</Point>
<Point Time="491348023">-2.40000</Point></Stat></Gather>
<State/>
<Checksum>19919658618FB888498D1D0A95C59705</Checksum></MissionProfile>

Here's my xsl which, gets me the Min and Max values of "Point"...Now I need to extract the greatest Absolute value of the two, but obviously can't use the abs() function due to 1.0 vs. Can anyone help? I've nearly worn out my keyboard trying to make a global variable work...NO Joy! Thanks...

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:variable name="points"
select="/MissionProfile/Gather/Stat/Point" />
<xsl:variable name="minNumber"
select="$points[not (. &gt; $points)]" />
<xsl:variable name="maxNumber"
select="$points[not (. &lt; $points)]" />
<xsl:template match="/MissionProfile">
<html>
<h2>Here's your Dead Reckoning results:</h2>
<body>
<xsl:text>Course Maximum Variations = </xsl:text>
<xsl:for-each select="Gather/Stat/Point">
<xsl:sort select="." data-type="number"/>
<xsl:if test="position()=last()">
<xsl:value-of select="format-number(.,'#.00')"/>
<xsl:text> Deci-Miles Right, </xsl:text>
</xsl:if>
<xsl:if test="position()=1">
<xsl:value-of select="format-number(-1*.,'#.00')"/>
<xsl:text> Deci-Miles Left, </xsl:text>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Last edited by JakeRogers; November 5th, 2013 at 04:53 PM..
 
Old November 3rd, 2013, 07:09 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The easiest way to get the absolute value of a number in 1.0 is probably

Code:
number(translate(string($x), '-', '')
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 4th, 2013, 11:17 AM
Authorized User
 
Join Date: Jun 2013
Posts: 13
Thanks: 0
Thanked 1 Time in 1 Post
Default

For others who might need this solution...here it is:
<xsl:for-each select="Gather">
<xsl:text>Course Maximum Variation = </xsl:text>
<xsl:if test="-1*$minNumber &gt; $maxNumber">
<xsl:value-of select ="format-number(-1*$minNumber,'#.00')"/>
<xsl:text> Deci-Miles Right, </xsl:text>
</xsl:if>
<xsl:if test="-1*$minNumber &lt; $maxNumber">
<xsl:value-of select ="format-number($maxNumber,'#.00')"/>
<xsl:text> Deci-Miles Left, </xsl:text>
</xsl:if>
</xsl:for-each>

Edit: Anyone? Anyone?

Thanks but not much help...I know my min will ALWAYS be - and my max ALWAYS +. Thus, I simply multiply min by -1...Problem is I end up with 2 numbers from which I wish to display the larger! Other ideas? Thanks and btw, I've ordered your book!

Last edited by JakeRogers; November 5th, 2013 at 04:50 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to extract appended xml's into single xml's using XSL veeka01 XSLT 1 July 30th, 2011 08:22 PM
Retrieving a single value from a single column in a single row? Ron Howerton LINQ 2 May 17th, 2011 08:46 AM
Representing multiple items with a single value? Donny Bahama Classic ASP Professional 1 January 16th, 2006 09:32 PM
Retreive latest and greatest record alexvgs Oracle 3 April 25th, 2005 09:57 PM
getting the greatest number skicrud Beginning PHP 4 August 10th, 2004 11:46 AM





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