Subject: RE: [xsl] 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 |
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: [xsl] 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 > 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] sorting the result of a c, Ragulf Pickaxe | Thread | Re: [xsl] sorting the result of a c, Ragulf Pickaxe |
Re: [xsl] nesting flat XML based on, David Carlisle | Date | Re: [xsl] sorting the result of a c, Ragulf Pickaxe |
Month |