Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XSL Summation upon a node substring contidional

Posted on 2011-02-23
6
Medium Priority
?
514 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
The viewer will learn how to dynamically set the form action using jQuery.
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…

715 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