Using XSLT2 id() Function in Schematron

Here should go questions about transforming XML with XSLT and FOP.
SoosCreek
Posts: 2
Joined: Tue Sep 29, 2009 12:55 am

Using XSLT2 id() Function in Schematron

Post by SoosCreek »

I'm having difficulty with what I thought would be a rather simple attempt to use the XQuery/XLST id function to find the correct element associated with a specific id reference. Here's my Schematron attempt to get ANY value at all from the id function:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns uri="MyTargetNamespace" prefix="ns"/>
<title>Simple Sample to Make the XQuery id() function work from within Schematron</title>
<pattern>
<rule context="ns:MyXmlDocument">
<let name="sRef" value="Vehicle/VehicleDriver/@idref"/>
<assert test="0=1">
Driver Reference: |<value-of select="$sRef"/>|
Driver Name: |<value-of select="id($sRef)"/>|
</assert>
</rule>
</pattern>
</schema>
What am I doing wrong? Does oXygen support the id() function? I'll post the .xsd and .xml examples in the next post in case you want to see how it's not working.

Thanks for any advice you can give!

Joel Byford
SoosCreek
Posts: 2
Joined: Tue Sep 29, 2009 12:55 am

Re: Using XSLT2 id() Function in Schematron

Post by SoosCreek »

Here is the sample XML Schema Document (XSD):

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="MyTargetNamespace"
targetNamespace="MyTargetNamespace">

<xsd:element name="MyXmlDocument" type="XmlDocumentType"/>

<xsd:complexType name="XmlDocumentType">
<xsd:sequence>
<xsd:element name="Person" type="PersonType" maxOccurs="unbounded"/>
<xsd:element name="Vehicle" type="VehicleType"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="PersonFirstName" type="xsd:string"/>
<xsd:element name="PersonSurName" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>

<xsd:complexType name="VehicleType">
<xsd:sequence>
<xsd:element name="VehicleIdentification" type="xsd:string"/>
<xsd:element name="VehicleCommercialIndicator" type="xsd:boolean"/>
<xsd:element name="VehicleDriver" type="VehicleDriverType"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="VehicleDriverType">
<xsd:attribute name="idref" type="xsd:IDREF"/>
</xsd:complexType>


</xsd:schema>
Here is a simple instance conformant with that XSD:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<ns:MyXmlDocument xmlns:ns="MyTargetNamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="MyTargetNamespace file:/C:/Users/Joel%20Byford/Documents/My%20Archives/SimpleSchema.xsd">
<Person id="P1">
<PersonFirstName>John</PersonFirstName>
<PersonSurName>Doe</PersonSurName>
</Person>

<Person id="P2">
<PersonFirstName>Jane</PersonFirstName>
<PersonSurName>Smith</PersonSurName>
</Person>

<Vehicle>
<VehicleIdentification>abc123</VehicleIdentification>
<VehicleCommercialIndicator>true</VehicleCommercialIndicator>
<VehicleDriver idref="P1"/>
</Vehicle>



</ns:MyXmlDocument>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Using XSLT2 id() Function in Schematron

Post by george »

Hi,

In Options->Preferences -- XML -- XML Parser in the ISO Schematron section enable the Use Saxon schema-aware for xslt2 query binding option.

Note that you will need to change also the Schematron file to select something inside the element selected by the ID function, for example I changed that to select all the text nodes like below

Code: Select all

Driver Name: |<value-of select="id($sRef)//text()"/>|


and the result was as below, where you can see that the id function works:

Code: Select all

SystemID: /Users/george/test/test2.xml
Engine name: ISO Schematron (XSLT 2.0)
Severity: error
Description: Driver Reference: |P1| Driver Name: |JohnDoe| (0=1)
Start location: 5:0
Best Regards,
George
George Cristian Bina
Post Reply