This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I'm here with another newbie question - how can I easily tell whether attributes exist or not?
Given the following XML snippet....
I have certain elements with the Complexity, Impact etc... attributes and others without. For the ones without attributes I want to insert pre-defined default values into my output CSV file. For the ones with attributes I want to use the values from the XML document.
I have tried comparing the value of @Attribute to '' in an xsl:if which doesn't seem to work (it always returns false regardless of whether @Attribute exists or not) and I tried testing for the attribute itself, like so...
...but this always returns true if the Complexity attribute exists - I want to be able to negate that test to return true if it doesn't exist.
More precisely, "@Attribute" returns a node list. When coerced to boolean (as in your <xsl:if test=""> example) the node list becomes true if it contains any nodes and false if not. Passing it to the not() function, as Matthew suggests, also coerces it to boolean, so therefore applying not() results in false if the node list contains any nodes and true if it is empty.
Joined: Aug 17, 2005
Thanks again Paul, using the not() function did exactly what I wanted!