Xslt - programming methods

A question about Oliver Becker's effective xslt programming methods at this link.

We know that using this code, we can eliminate the multi-valued xsl selection method

concat( substring(Str1,1 div Cond), substring(Str2,1 div not(Cond)) ) 

However, what can we indicate in a โ€œconditionโ€ just to check for the presence or absence of nodes?

we cannot indicate

 concat( substring(Str1,1 div test="/node"), substring(Str2,1 div not(test="/node")) ) 

which throws syntax errors.

0
xml xslt
source share
1 answer

Try this expression (where node is the name of the node you want to test):

 <xsl:value-of select="concat( substring('Yes', 1 div not(not(/root/node))), substring('No', 1 div not(/root/node)))"/> 

Or better yet

 <xsl:value-of select="concat( substring('Yes', 1 div boolean(/root/node)), substring('No', 1 div not(/root/node)))"/> 

When applied to this XML, it displays Yes

 <root> <node>Test</node> </root> 

But when applied to this XML, No

 <root> <othernode>Test</othernode> </root> 
+2
source share

All Articles