Subject: [xsl] sorting the result of a calculation on xml that can have missing/blank tags From: <srguard2000-triallicense@xxxxxxxxxxx> Date: Wed, 14 Dec 2005 11:07:07 +0000 (GMT) |
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 > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] counting in for each, Andrew Franz | Thread | Re: [xsl] sorting the result of a c, Ragulf Pickaxe |
Re: [xsl] counting in for each, Andrew Franz | Date | Re: [xsl] nesting flat XML based on, David Holden |
Month |