xsl-list
[Top] [All Lists]

sorting the result of a calculation on xml that can have missing/blank tags

2005-12-14 04:07:07
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--