OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Catalog Resolver for XSD and XSLT

Hi Michael,

> I think you are asking about how to do this in the Java world - the answer for

Yes, Java.

> With the Saxon API you can do the schema validation as you parse the

My understanding is that Saxon 9 does not have full XSLT 1 support.
Unfortunately, both XSLT 1 and XSLT 2 documents are used.

If it was only XSLT 2, then it would be easier, but still problematic.

The XsltTransformer cannot use XmlCatalogResolver because it does not
implement the URIResolver interface. That seems a bit strange.
Nevertheless, the first step to a working solution resembles:

// From org.apache.xml.resolver.tools ...
CatalogResolver resolver = new CatalogResolver();
Configuration config = new Configuration();
config.setURIResolver( resolver ):
Processor p = new Processor( config );
XsltExecutable exec = p.newXsltCompiler().compile( stylesheet );
XsltTransformer t = exec.load();
t.setSchemaValidationMode( ValidationMode.STRICT );
t.transform( source, destination );

There's a wrench in the works. Some XML documents specify the
stylesheet with the "xml-stylesheet" processing instruction. Such as:

<?xml-stylesheet type="text/xsl"

This means that the XsltExecutable instance must derive the stylesheet
using the catalog resolver. There is no "stylesheet" parameter, per
se. However, an XsltCompiler instance requires a stylesheet, as per
its API:

XsltExecutable exec = p.newXsltCompiler().compile( stylesheet );

There must be a way to get the stylesheet path first. This implies
parsing (loading) the XML document prior to transforming. Thus simply
parsing the XML document must also use a catalog resolver.

Otherwise, it requires extracting the processing instruction to
determine the path to the XSL file, then resolving it using the
catalog resolver. Manual extraction of the processing instructions is
brittle and introduces a lot of code.

Unless I am mistaken, using a catalog resolver with S9 is only a minor
reduction in code. Overall, it appears to have similar deficiencies as

> No mention here of a catalog resolver, but you can use one if you want.

How do you use a catalog resolver, an XSD for vaildation, and an XSL
template URI specified in the XML document (to validate and
transform)? For example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model type="application/xml"
<?xml-stylesheet type="text/xsl"
    <title>Shopping List</title>
    <body>headlight fluid, flamgrabblit, exhaust coil</body>

How would the above XML be validated and transformed using S9's API
alone? (Presumably the transformation step would not happen if the XML
file failed validation.)

Thank you.

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS