[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: sorting the result of a calculation on xml that ca

Subject: RE: sorting the result of a calculation on xml that can have missing/blank tags
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 14 Dec 2005 11:59:54 -0000
blank tags
Dealing with missing elements and empty elements are actually two slightly
different problems.

However, to get a default value of "0", 

 number(concat('0', string(HomePupils)))

works in both cases.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: srguard2000-triallicense@xxxxxxxxxxx 
> [mailto:srguard2000-triallicense@xxxxxxxxxxx] 
> Sent: 14 December 2005 11:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  sorting the result of a calculation on xml 
> that can have missing/blank tags
> 
> XSL Processor: Xalan C++ 1.8.0
> on MSVC6.0 and MS Windows XP Professional
> 
> Hello, I am new to this list and have a question about XSL.
> 
> I need to sort the results of an xsl calculation, while 
> allowing for tags that are missing or
> empty.
> I tried using format-number() to replace blanks with '0' and 
> even 'number(0)', but when the output
> of format-number is used in a calculation, the result is NaN.
> 
> The result should have "CALC div: 5" as the first item.  The 
> result is just text at the moment.
> 
> I'm under time pressure to get this working... tempting to 
> just do it in C++ but it would be nicer
> to have it in xsl...
> 
> Thanks!
> 
> Sean
> 
> 
> 
> Sample XML:
> ===========
> <?xml version="1.0" encoding="UTF-8"?>
> <Message>
> 	<Classes>
> 		<Class>
> 			<Teachers>2</Teachers>
> 			<HomePupils></HomePupils>
> 			<GuestPupils>10</GuestPupils>
> 		</Class>
> 	</Classes>
> </Message>
> 
> Sample XSL:
> ===========
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> 
> 	<xsl:decimal-format name="CCMDecimalFormat" NaN="0" />
> 
> 	<xsl:template match="*">
> 		<xsl:for-each select="//Classes/Class[(		
> 									
> Teachers &gt; 0 )]">
> 			<xsl:sort select="(HomePupils + 
>  GuestPupils)	div Teachers" data-type="number" order="descending"/>
> 			<!--xsl:if test="position()=1"-->
> 								
> 				HP:<xsl:value-of 
> select="HomePupils"/> ; 
> 								
> 				GP:<xsl:value-of 
> select="GuestPupils"/> ; 
> T:<xsl:value-of select="Teachers"/> ; 
> 
> 								
> 				CALC number: <xsl:value-of 
> select="HomePupils"/>
> 
> 								
> 				CALC sum: <xsl:value-of 
> select="HomePupils + 
> GuestPupils"/>
> 
> 								
> 				CALC div: <xsl:value-of select="
> (HomePupils + 
> GuestPupils div Teachers)		"/>
> 			<!--/xsl:if-->
> 			
> 			==============
> 		</xsl:for-each>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> 
> 
> ___________
> Sean Ryan

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.