Solved

XSL Summation upon a node substring contidional

Posted on 2011-02-23
6
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

623 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