Solved

XSL Summation upon a node substring contidional

Posted on 2011-02-23
6
508 Views
Last Modified: 2013-11-18
Greetings,

The basic scenario is simple: sum a series of values.
<xsl:value-of select="sum(nodeA/nodeB/value)"/>

Open in new window


The catch:
I want to sum all values except where the value of nodeB has a substring at the end the contains 2 specific characters. They are utilized as identifiers.

I know that this substring comparison works correctly (where Var2 has a string length of 2):
<xsl:when test="substring($Var1, (string-length($Var1) - string-length($Var2))+1) = 'XY'">

Open in new window


So, I was thinking that I could apply that same logic within the summation methodology

<xsl:variable name="Var3" select="sum(nodeA/nodeB[substring(/ValueOfNodeB, (string-length(/ValueOfNodeB) - string-length('XY'))+1) != 'XY']/nodeC/nodeD)"/>

Open in new window


I think that I am very close, and in fact the above line compiles and performs the summation, but doesn't perform the exclusion.

I would appreciate any thoughts or guidance.

Thanks in advance.
0
Comment
Question by:nmluthy
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34964658
the "/" makes the XPath return all values friom the root
I think you need

<xsl:variable name="Var3" select="sum(nodeA/nodeB[substring(., (string-length(.) - string-length('XY'))+1) != 'XY']/nodeC/nodeD)"/>

But basically this is the right approach and should work
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34964672
safer is

<xsl:variable name="Var3" select="sum(nodeA/nodeB[not(substring(., (string-length(.) - string-length('XY'))+1) = 'XY')]/nodeC/nodeD)"/>

"=" in predicates is set compare, that could be tricky
0
 

Author Comment

by:nmluthy
ID: 34964989
Thanks for you insight.

This will probably not look well upon me, but do you mean the "." as a literal or just shorthand notation for the values I had in there. I have seen "." used in much of the reference material I have found, but do not fully understand its purposed.

(If this is a totally new question I can move it to a new thread)

Thanks.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34965213
this is not a new question, don't worry

"." means the current node()
if you do eg.
nodeB[. = 'foo']
you will get all the nodeB that have the string 'foo' as content
0
 

Author Comment

by:nmluthy
ID: 34965348
Makes sense; I'm glad to definitely have learned something today.

I really appreciate your help! I'm glad to find out that I was quite close, but in the same context it is rather frustrating. But everything seems to work well now.

Cheers!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34965517
welcome
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to translate path in URL with PHP? 11 46
Web Development Tools for MVC 3 92
Form submit issue 11 85
Adjust the position 3 61
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question