[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How to compare two QName values in an XML Schema?


Subject: Re: [xsl] How to compare two QName values in an XML Schema?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 08 Apr 2011 18:14:04 +0200

Costello, Roger L. wrote:
Hi Folks,

Below is an XML Schema, containing two simpleTypes. The second one references the first.

I want an XPath expression that compares the second simpleType's reference to the name of the first simpleType:


/xs:schema/xs:simpleType[1]/@name eq /xs:schema/xs:simpleType[2]/xs:restriction/@base


That returns False. I want it to return True.


I figured the reason it's returning False is because it is comparing the string "elev:BostonAreaSurfaceElevation" against the string "EarthSurfaceElevation". Yes?

I want it to do a comparison of QNames, not strings. So I type-cast the values:


xs:QName(/xs:schema/xs:simpleType[1]/@name) eq xs:QName(/xs:schema/xs:simpleType[2]/xs:restriction/@base)


But that gave me this error:


Casting from xs:unTypedAtomic to xs:QName can never succeed.

Why?

I think the constructor (http://www.w3.org/TR/xquery-operators/#constructor-qname-notation) only works with a string literal as the argument.


What's the correct way to do the comparison?

With schema-aware processing (using the schema for schemas I guess) you should be able to compare
data(/xs:schema/xs:simpleType[1]/@name) eq data(/xs:schema/xs:simpleType[2]/xs:restriction/@base)
Otherwise you could use
resolve-QName(/xs:schema/xs:simpleType[1]/@name, /xs:schema/xs:simpleType[1]) eq resolve-QName(/xs:schema/xs:simpleType[2]/xs:restriction/@base, /xs:schema/xs:simpleType[2]/xs:restriction)


--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/


Current Thread