Hi,

no solution, but I can share my observations: 

* base-uri(.) in your example equals 'null'. On the other hand, the same 
happens for example when validating with Xerces in Oxygen.
* Saxon EE does validate your xsd OK. 

Looks like base-uri() is failing in general in this context with Xerces.

Not related, but I wondered years ago that xsd assertions on ancestor elements 
do work with Xerces.

Daniel

-----Ursprüngliche Nachricht-----
Von: BaseX-Talk <basex-talk-boun...@mailman.uni-konstanz.de> Im Auftrag von 
ykhab...@bellsouth.net
Gesendet: Mittwoch, 10. Juli 2024 21:18
An: basex-talk@mailman.uni-konstanz.de
Betreff: [basex-talk] XSD 1.1 validation: base-uri(.) in the assert

Hello,

We are using the final release BaseX 11.0 and Xerces 2.12.2 XSD 1.1 engine.

There is a need to validate XML file and check XML file name for naming 
convention.
Unfortunately, the assert with the base-uri(.) function is not working as 
expected in the assert expression.

Observations:
The XPath expression on the XML file emits, as expected, the following:
o       XPath: base-uri(.)
o       Results:
file:/C:/Users/i300179/Downloads/ATF_NESS/base-uri/input.xml

The XPath expression on the XML file emits, as expected, the following:
o       XPath: tokenize(base-uri(.),"/")[last()]
o       Results: input.xml

I tried multiple expressions around base-uri(.) function. None of them worked.
You will find all my attempts in the XSD file.

The test case XQuery/XML/XSD is below.

We are using Xerces, but the following Saxon excerpt could be pointing to the 
root cause of the problem.

For the reference:
https://www.saxonica.com/html/documentation10/functions/fn/base-uri.html
"It is possible for the base URI of a document to be absent (unknown). This 
happens when the document is supplied to Saxon with no location information:
for example when the node is represented using a tree model such as DOM that 
has no base URI information; or when a Source is supplied for which
getSystemId() returns null. The most common example of this is a Source created 
using new StreamSource(new FileInputStream("input.xml")). The problem can be 
fixed by using the second argument of the StreamSource constructor, or by using 
the constructor that expects a File rather than an InputStream."

XSD11_Validation.xq
=======================
declare variable $xml as xs:string external; declare variable $xsd as xs:string 
external;

let $result := validate:xsd-report($xml, $xsd, map {
'http://apache.org/xml/features/validation/cta-full-xpath-checking': true(),
'cache': false() })
return $result

input.xml
=======================
<root>
        <event>
                <id>1</id>
        </event>
</root>

input.xsd
========================
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1.0.1" attributeFormDefault="unqualified"
elementFormDefault="qualified"
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning";
  xmlns:xerces="http://xerces.apache.org"; vc:minVersion="1.1">
  <xs:element name="root">

    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="event"/>
      </xs:sequence>
      <!--<xs:assert test="ends-with(lower-case(string(base-uri(.))),
lower-case('.xml'))" xerces:message="Rule #21: XML file name shall match file 
naming convention">-->
      <xs:assert test="tokenize(base-uri(.), '/')[last()] eq 'input.xml'"
        xerces:message="Rule #21: XML file name shall match file naming 
convention">
      <!--<xs:assert test="string-length(tokenize(string(base-uri(.)),'/'))
lt 5" xerces:message="Rule #21: XML file name shall match file naming 
convention">-->
      <!--<xs:assert test="string-length(tokenize(string(base-uri(.)),
'/')[last()]) eq 4"
        xerces:message="Rule #21: XML file name shall match file naming 
convention">-->
      </xs:assert>
    </xs:complexType>
  </xs:element>

  <xs:element name="event">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="id"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="id" type="xs:integer"/> </xs:schema>


Regards,
Yitzhak Khabinsky


Reply via email to