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

RE: so how does sum() work?

Subject: RE: so how does sum() work?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 14 May 2008 08:45:20 +0100
RE:  so how does sum() work?
I can't see what's wrong here and I suspect the problem might be elsewhere.

One bit of advice, though: type errors are much easier to diagnose if you
declare the types of all your variables and parameters (using the "as"
attribute). This typically results in the error message being reported much
closer to the point where your code is actually wrong.

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

> -----Original Message-----
> From: Jacek Radajewski [mailto:jacekrad@xxxxxxxxx] 
> Sent: 14 May 2008 07:20
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  so how does sum() work?
> 
> Hi All,
> 
> I'm experiencing a strange (for me) behavior in my XSLT:
> 
> This works:
>         <xsl:for-each select="cdm:classification/cdm:app-domain">
>           <xsl:call-template name="print-assertion">
>             <xsl:with-param 
> name="business-rule">APP-0010</xsl:with-param>
>             <xsl:with-param name="message">A classification 
> to a Functional Application Domain must include a percentage 
> of use greater than
>               zero. </xsl:with-param>
>             <xsl:with-param name="result"
> select="number(@cdm:percent-of-use) &gt; 0"/>
>           </xsl:call-template>
>         </xsl:for-each>
> 
> 
> But this produces "required item type of first operand of '/' 
> is node; supplied value has item type xs:string"
>         <xsl:call-template name="print-assertion">
>           <xsl:with-param 
> name="business-rule">APP-0011</xsl:with-param>
>           <xsl:with-param name="message">An Application's 
> percentage of use across all non LOB domain classifications 
> must be equal to 100%. </xsl:with-param>
>           <xsl:with-param name="result"
> select="sum(cdm:classification/cdm:app-domain/@cdm:percent-of-
> use) = 1.0"/>
>         </xsl:call-template>
> 
> I'm using saxon 9B inside oxygen 9.2
> 
> Now if I execute
> sum(cdm:classification/cdm:app-domain/@cdm:percent-of-use) = 
> 1.0 within oxygen it correctly evaluates to either true or 
> false, but produces error when executing within my XSLT ... 
> but only if the result evaluates to false.  When the sum of 
> those attributes does equal 1.0 then no error is generated.
> 
> 
> Any ideas?
> 
> Thanks in advance
> 
> Oh, BTW: I call my print-assertion template maybe 40 times in 
> my stylesheet and all works well.  Its only the sum() that is 
> causing me grief.
> 
> Jacek
> 
> ----------- print-assetrion template --------------------  
> <xsl:template name="print-assertion">
>     <xsl:param name="result" select="false()"/>
>     <xsl:param name="element"/>
>     <xsl:param name="business-rule"/>
>     <xsl:param name="message"/>
>     <xsl:if test="not($result) or $print-passed-assertions">
>       <assertion>
>         <asset-id>
>           <xsl:value-of
> select="$element/ancestor-or-self::node()[ends-with(name(),
> '-asset')]/@cdm:uuid"/>
>         </asset-id>
>         <asset-name>
>           <xsl:value-of
> select="$element/ancestor-or-self::node()[ends-with(name(),
> '-asset')]/cdm:name"/>
>         </asset-name>
>         <business-rule>
>           <xsl:value-of select="$business-rule"/>
>         </business-rule>
>         <result>
>           <xsl:value-of select="$result"/>
>         </result>
>         <element>
>           <xsl:copy-of select="$element"/>
>         </element>
>         <message>
>           <xsl:copy-of select="$message"/>
>         </message>
>       </assertion>
>     </xsl:if>
>   </xsl:template>
> 
> --
> Jacek Radajewski

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.