xsl-list
[Top] [All Lists]

Re: [xsl] XPath 1.0 challenge: select all XML Schema element declarations with type string

2015-07-19 15:26:08
On 2015-07-19 15:58, Costello, Roger L. costello(_at_)mitre(_dot_)org wrote:
Hi Folks,

The following XPath expression returns all XML Schema element
declarations with @type equal to xs:string:

        //xs:element[@type = 'xs:string']

However, that XPath assumes the schema file is written with a
namespace prefix, like this:

        <xs:element name="Test" type="xs:string" />

But the schema file could have been written like this:

        <element name="Test" type="string" />

There are two issues here. The first is matching the element called 'element' and your XPath expression will work fine there, assuming you've bound the prefix "xs" to the XML Schema namespace URI and that the same namespace name is the default namespace for the prefix-less Schema document.

The second issues is matching "string" or xs:string". We know that it's a QName and must have zero or one colon, so
    @type = "string" or substring-after(@type, ":") = "string"
would work.

Liam


--
Liam Quin, W3C - XML Activity Lead; Digital publishing; HTML Accessibility

Pictures From Old Books http://www.fromoldbooks.org/ ; words at http://words.fromoldbooks.org Coming soon: punctuation from old books, instalment one: Just the Commas.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>