Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XSLForum: Main > XSL Coding General

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-11-2008, 06:30 PM
Steph
 
Posts: n/a

Default Sum Returns 0



Hello,

I can't get simple addition to work in my xsl file. Here's some of the XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<myFields
xmlns="http://schemas.microsoft.com/office/infopat h/2003/myXSD/2008-10-08T18:17:49">...
<groupServers>
<txtNoCPU>5</txtNoCPU>
<txtReqNtwrkBandw>2</txtReqNtwrkBandw>
</groupServers>
<groupServers>
<txtNoCPU>4</txtNoCPU>
<txtReqNtwrkBandw>8</txtReqNtwrkBandw>
</groupServers>
</myFields>


Here's some of the XSL:

<xsl:template match="/ns2:myFields">
<xsl:apply-templates select="//txtNoCPU"/>
<w><w:r><w:t>
<xsl:text>TOTALS test</xsl:text>
</w:t></w:r></w>
<w><w:r> <w:t>
<xsl:text>CPUs </xsl:text>
<xsl:value-of select="sum(//txtNoCPU)"/>
</w:t></w:r></w>
</xsl:template>


And this is the result of the transform:

TOTALS test
CPUs 0

Instead of 0, I expected 9. I've tried everything I can think of, but I'm
running out of ideas. (At least the groupServers stuff no longer disappears
entirely, and no more NaN)

I started with an Infopath 2003 form, then opened the xml in Word 2003 and
formatted it. Then I used the wml2xslt tool to create the xsl file. The
original Infopath form did the addition I wanted, but it wouldn't come across
to Word. (I tried getting the code from InfoPath and adding it back in with
no luck).

Any ideas? (I'm a beginner...)


Thanks, Steph
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-11-2008, 06:30 PM
Steph
 
Posts: n/a

Default Re: Sum Returns 0

It worked! Thank you so much!

Steph

"Martin Honnen" wrote:

> Steph wrote:
>
> > <myFields
> > xmlns="http://schemas.microsoft.com/office/infopat h/2003/myXSD/2008-10-08T18:17:49">...
> > <groupServers>
> > <txtNoCPU>5</txtNoCPU>

>
> The default namespace declaration on the myFields element applies to
> descendant elements as well meaning your txtNoCPU elements are in the
> namespace
> http://schemas.microsoft.com/office/...10-08T18:17:49.
> So in your XSLT 1.0 stylesheet you need to bind a prefix to that
> namespace URI and use that prefix to qualify element names e.g.
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0"
>
> xmlns:df="http://schemas.microsoft.com/office/info path/2003/myXSD/2008-10-08T18:17:49">
>
>
> <xsl:template match="df:myFields">
> <xsl:value-of select="sum(.//df:txtNoCPU)"/>
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 12:37 PM.
Style Developed by Epic Designz