Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test for missing attribute in XSL?

Tags:

xslt

xpath

What I have is following:

<xsl:variable name="myvar" select=".//spss:category[((not @varName) or @varName=$colVarName) and @text=$series]/spss:cell/@text"/>

What it should do is select the text of the spss:cell's text-Attribute as long as it is a child of a spss:category that has

  • either a varName Attribute with a value equal to $colVarName
  • OR no varName Attribute at all

What is happening is following error message (sorry translating here, so just the gist of it):

Expected Token ')'. Found Token '@'.
.//spss:category[((not -->@<-- varName) or @varName=$colVarName...

Problem Solved! (See below)

like image 336
Daren Thomas Avatar asked Jan 22 '09 13:01

Daren Thomas


2 Answers

OK, I think I found the mistake:

not must be used with parenthesis, so instead of

(not @varName) or @varName=$colVarName

it should have been

not(@varName) or @varName=$colVarName
like image 134
Daren Thomas Avatar answered Nov 05 '22 21:11

Daren Thomas


indeed - not() is a function that returns the boolean opposite of whatever is between the parens. If necessary - it will cast its argument to a boolean. In this case, an empty node set casts automatically to false, so if @varName gives you an empty node set, not(@varName) will be true.

like image 42
Dominic Cronin Avatar answered Nov 05 '22 20:11

Dominic Cronin