Solved

XSL Summation upon a node substring contidional

Posted on 2011-02-23
6
501 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now