Subject: Re: [xsl] Why does this XPath expression work fine when run inOxygen but fails when used in an XSD 1.1 assert element? From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 2 Dec 2019 18:40:58 -0000 |
You're confusing two things here. Firstly, there's an absolute rule that an assertion can only look within the subtree of the element on which it is defined. In other words, an assertion on an element can make that element invalid, but it can't make other elements invalid (other than containing elements of course). That's fundamental to the XSD concept that the outcome of validation is not just a yes/no answer, but an annotated document (PSVI) in which valid and invalid elements can be distinguished. Secondly, the spec says that by default, assertions can't see comments and PIs. In other words, users can add comments and PIs to the instance without worrying about whether the schema allows them. Again, that's based on a theory about what comments and PIs are intended for. But here the spec relaxes the rules, and says that "at user option" comments and PIs can be made visible to assertions. Saxon provides such an option (--assertionsCanSeeComments:true on the command line). But they're only visible if they're in the subtree of the element being validated. Michael Kay Saxonica > On 2 Dec 2019, at 18:12, Costello, Roger L. costello@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Thank you Graydon and Ken. > > If I understand correctly, you are saying that the XPath expression in an XSD 1.1 assert may not reference comment fields. Correct? > > Okay, I will switch back to XSD 1.0 and express assertions using Schematron. The XPath works fine in Schematron: > > <sch:rule context="xhtml:html/xhtml:head"> > <sch:assert test="xhtml:style/following-sibling::comment()[1]/starts-with(., '[if gte mso 9]><xml>')"> > Two comments may occur following the > style element; they must contain a > well-defined content > </sch:assert> > </sch:rule> > > /Roger > > -----Original Message----- > From: G. Ken Holman g.ken.holman@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Monday, December 2, 2019 12:50 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [EXT] Re: [xsl] Why does this XPath expression work fine when run inOxygen but fails when used in an XSD 1.1 assert element? > > The data model within which an assertion is evaluated is comprised only of the element itself, not its siblings. You are looking at siblings. > > Per the specification: > > https://www.w3.org/TR/xmlschema11-1/#sec-cvc-assertion > > I hope this helps. > > . . . . . . Ken > > At 2019-12-02 17:27 +0000, Costello, Roger L. costello@xxxxxxxxx wrote: >> Hi Folks, >> >> Below is a sample XHTML document. Immediately following the <style> >> element is a comment. I want to ensure that the value in the comment >> starts with this string: >> >> [if gte mso 9]><xml> >> >> Using Oxygen, I ran the following XPath query (the <head> element is >> the context node): >> >> *[local-name() eq >> 'style']/following-sibling::comment()[1]/starts-with(., '[if gte mso >> 9]><xml>') >> >> The result of running the query is: >> >> true() >> >> Perfect! >> >> Next, I put the query into an XML Schema 1.1 assert element: >> >> <xs:assert test="*[local-name(.) eq >> 'style']/following-sibling::comment()[1]/starts-with(., '[if gte mso >> 9]><xml>')" /> >> >> When I validated the XHTML document against the XML Schema, I got this error: >> >> Assertion evaluation ('*[local-name(.) eq >> 'style']/following-sibling::comment()[1]/starts-with(., '[if gte mso >> 9]><xml>')') for element 'head' on schema type 'headType' did not succeed. >> >> Why does the XPath query work fine when run in Oxygen but fails when >> used in an XSD 1.1 assert element? /Roger >> >> Here's the XHTML document: > > > -- > Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ | Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) | Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Why does this XPath expre, Costello, Roger L. c | Thread | Re: [xsl] Why does this XPath expre, Mukul Gandhi gandhi. |
Re: [xsl] Why does this XPath expre, Michael Kay mike@xxx | Date | Re: [xsl] current() and position()?, David Birnbaum djbpi |
Month |