Link to home
Start Free TrialLog in
Avatar of nmluthy
nmluthy

asked on

XSL Summation upon a node substring contidional

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.
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

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
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nmluthy
nmluthy

ASKER

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.
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
Avatar of nmluthy

ASKER

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!