Your schema requires a quantity attribute to be present on the root element,
not on the purchase element.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Costello, Roger L.
> Sent: 18 February 2008 19:03
> To: saxon-help@...
> Subject: [saxon] Schema-aware comparison of a positiveInteger
> and a string... error message incorrect?
>
> Hi Folks,
>
> Consider this XML of a purchase (this is a simplified version
> of an example in Michael Kay's XPath 2.0 book):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="purchase.xsd">
> <purchase quantity="1">Shirt</purchase> </root>
>
> Here is the XPath I wish to execute:
>
> if (@quantity = 'out-of-stock') then xs:nonNegativeInteger(0)
> else xs:nonNegativeInteger(@quantity)
>
> When I execute it using SAXON 9.0.0.3j with the -val option I get this
> error:
>
> Validation error on line 3 column 51 of purchase.xml:
> XTTE1510: Required attribute @quantity is missing (See
> http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 4)
> Transformation failed: Run-time errors were reported
>
> I understand that an error should be generated since
> @quantity has a positiveInteger value and the XPath is
> comparing it against a string.
>
> But I am confused by the error message, which says that
> "@quantity is missing." Clearly @quantity is present in the
> XML document.
>
> Further, I am confused by why it is a "run-time error."
> Shouldn't it be a static error?
>
> There are two possibilities:
>
> 1. I am not understanding some important issue, and the error
> message is correct.
>
> 2. The error message is incorrect.
>
> Which is the case?
>
> Below is my XSLT stylesheet and XML Schema. /Roger
>
> --------------------------------------------------------
> XSLT STYLESHEET
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> version="2.0">
>
> <xsl:output method="text"/>
>
> <xsl:import-schema schema-location="purchase.xsd"/>
>
> <xsl:template match="purchase">
> <xsl:value-of select="if (@quantity = 'out-of-stock') then
> xs:nonNegativeInteger(0)
> else xs:nonNegativeInteger(@quantity)"/>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> --------------------------------------------------------
> XML SCHEMA
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>
> <xs:element name="root">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="purchase" maxOccurs="unbounded"/>
> </xs:sequence>
> <xs:attribute name="quantity" type="quantity-type"
> use="required" />
> </xs:complexType>
> </xs:element>
>
> <xs:element name="purchase" type="xs:string"/>
>
> <xs:simpleType name="quantity-type">
> <xs:union memberTypes="xs:positiveInteger out-of-stock" />
> </xs:simpleType>
>
> <xs:simpleType name="out-of-stock">
> <xs:restriction base="xs:string">
> <xs:enumeration value="out-of-stock" />
> </xs:restriction>
> </xs:simpleType>
>
> </xs:schema>
>
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> saxon-help mailing list archived at
> http://saxon.markmail.org/ saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help
|