XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Haseeb HassanSubject: Verifying XML and XSD within XSLT
Author: Haseeb Hassan
Date: 09 Dec 2007 03:44 PM
I have to design an XSLT that verifies an XML file on an specific schema.
like if i have following XSD,

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="language" type="xs:string"/>
<xs:element name="ISBN" type="xs:long"/>
<xs:element name="price" type="xs:float"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

and an XML file like,

<?xml version="1.0" encoding="UTF-8"?>
<library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test1.xsd">

<book>
<title>The World as i see it</title>
<author>ABC</author>
<language>English</language>
<ISBN>123456789</ISBN>
<price>12.99</price>
</book>

<book>
<title>Da Vinci Code</title>
<author>Dan Brown</author>
<language>English</language>
<ISBN>123456789</ISBN>
<price>14.99</price>
</book>

</library>


my XSLT should verify if this XML conforms to the above mentioned schema.
N.B. this schema can be flexible so could be the XML and the XSLT should stand by even in such scenario.


UnknownNoname(37).

Postnext
Alberto MassariSubject: Verifying XML and XSD within XSLT
Author: Alberto Massari
Date: 11 Dec 2007 10:50 AM
Hi,
there is no instruction in XSL to validate a piece of XML; but each processor can optionally validate its input, via specific options. For instance, if you display the Scenario Settings dialog for an XSLT document opened inside Stylus Studio, select Saxon as processor and click on the Settings button, you can specify to use the Schema-aware processor and tell him to perform a Strict source document validation.

Hope this helps,
Alberto

Postnext
Haseeb HassanSubject: Verifying XML and XSD within XSLT
Author: Haseeb Hassan
Date: 12 Dec 2007 05:12 AM
Thanks for that but the thing is that you can not show an output using the depending on the success or failure of XML doc and schema. I need some reference regarding this.

Posttop
Alberto MassariSubject: Verifying XML and XSD within XSLT
Author: Alberto Massari
Date: 12 Dec 2007 11:32 AM
Hi,
this is not possible in normal XSLT 1.0. Even in XSLT 2.0 and XQuery 1.0 (that support the concept of validating arbitrary nodes) a failed validation would stop the processing with a runtime error.
The only choice left would be writing inside Stylus Studio a pipeline that contains a Validate node followed by two XSLT nodes, one being executed when the document is valid and one when the document is invalid.

Hope this helps,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.