In XSLT 2.0, can an attribute be compared to a namespace inside a predicate?
I have the following partial xpath expression
IAAXML:party[@xsi:type='IAAXML:Organization']
My original XML:
<IAAXML:party xsi:type="IAAXML:Organization">
With the namespace declared as such:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
I am getting the following error:
The operand types are not compatible for the = operator
How do I compare this attribute using a namespace?
source to share
JLRishe essentially gave you the answer, but I'll strengthen it. The attribute xsi:type
is of type QName. Therefore, in a processor supporting the schema, your comparison is a typed comparison between a QName and a string, which is not allowed for very good reasons. After all, your application logic should not depend on the source document using the IAAXML namespace prefix and not some other author prefix. Given that you have a type-aware processor, it would be better to compare the QName:
[@xsi:type = QName("http://the-iaaxml-namespace/", "Organization")]
source to share
xsi:type
as schema type references (which, as Michael explained, are identified by their QName). So the processor won't let you just compare it to a string value. Assuming you are using the same namespace prefix for that type namespace in both the original document and this string value, it looks like this works (and should work on any processor):
IAAXML:party[string(@xsi:type) = 'IAAXML:Organization']
But Michael's suggestion to use QName with a namespace URI would be a more reliable approach in a schema-aware processor like yours.
source to share