XSD and Schematron - Problem using variables
Posted: Thu Aug 10, 2006 7:05 pm
I am new to XSD and Schematron and would like to know if anybody has successfully implemented variable using the new ISO Schematron element 'let' (vaiables).
I have a simple XSD and XML example below. When validating the XML I receive the following error:
Description: Failed to compile stylesheet. 1 error detected.
Description: XPath syntax error at char 8 on line 18 in {$theuser='B'}:
Variable $theuser has not been declared
The XSD file:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron">
<xs:annotation>
<xs:appinfo>
<sch:title>Schematron validation schema for Portal Client</sch:title>
<sch:ns prefix="C" uri="http://example.com/po-schematron" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Client" >
<xs:complexType>
<xs:sequence>
<xs:element name="UserId" type="xs:string" minOccurs="0" >
<xs:annotation>
<xs:appinfo>
<sch:pattern name="UserId Required Fields\">
<sch:rule context="C:UserId ">
<sch:let name="theuser" value="text()"/>
<sch:assert test="$theuser='B'">User is invalid</sch:assert>
<sch:assert test="../C:clientId[text()]">Client Id is required </sch:assert>
<sch:assert test="../C:CompanyName[text()]">CompanyName is required</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="clientId" type="xs:string" minOccurs="0" />
<xs:element name="CompanyName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML content:
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen SCHSchema="client.xsd"?>
<Client xmlns="http://example.com/po-schematron"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserId></UserId>
<clientId></clientId>
<CompanyName></CompanyName>
</Client>
I have a simple XSD and XML example below. When validating the XML I receive the following error:
Description: Failed to compile stylesheet. 1 error detected.
Description: XPath syntax error at char 8 on line 18 in {$theuser='B'}:
Variable $theuser has not been declared
The XSD file:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron">
<xs:annotation>
<xs:appinfo>
<sch:title>Schematron validation schema for Portal Client</sch:title>
<sch:ns prefix="C" uri="http://example.com/po-schematron" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Client" >
<xs:complexType>
<xs:sequence>
<xs:element name="UserId" type="xs:string" minOccurs="0" >
<xs:annotation>
<xs:appinfo>
<sch:pattern name="UserId Required Fields\">
<sch:rule context="C:UserId ">
<sch:let name="theuser" value="text()"/>
<sch:assert test="$theuser='B'">User is invalid</sch:assert>
<sch:assert test="../C:clientId[text()]">Client Id is required </sch:assert>
<sch:assert test="../C:CompanyName[text()]">CompanyName is required</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="clientId" type="xs:string" minOccurs="0" />
<xs:element name="CompanyName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML content:
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen SCHSchema="client.xsd"?>
<Client xmlns="http://example.com/po-schematron"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserId></UserId>
<clientId></clientId>
<CompanyName></CompanyName>
</Client>