Validating XML files during a transformation

Here should go questions about transforming XML with XSLT and FOP.
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Validating XML files during a transformation

Post by mlcook »

Is it possible to validate XML files during an XSL transformation before actually performing the transformations?

That is, I'd like to make sure the input XML file is valid before trying to process it.

I would know which schema to use.

Although the XML files should have been validated before the transformation, I can't guarantee it, so I'd like to make a check to verify them.

Is this possible with XSL?

If so, how?

Thanks, Mike
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Validating XML files during a transformation

Post by sorin_ristache »

Hello,

For DTD based validation of the XML input of the transformation use Saxon 9 to apply the transformation and enable the option DTD based validation of the source file in Options -> Preferences -> XML -> XSLT/FO/XQuery -> XSLT -> Saxon -> Saxon 9. For XML Schema based validation you need the schema-aware version of Saxon 9, that is Saxon 9 SA and you need to enable the option Schema based validation of the source file available in the same Preferences panel.


Regards,
Sorin
mlcook
Posts: 67
Joined: Thu Jan 24, 2008 4:52 pm

Re: Validating XML files during a transformation

Post by mlcook »

I was thinking of XML schema aware validation during XSLT transformations. Since we don't have Saxon 9SA, that option is out for the moment.

I had seen this web page:
http://www.ibm.com/developerworks/xml/l ... axslt.html
which uses
<xsl:import-schema schema-location="po1.xsd"/>
and then
<xsl:template match="document-node(schema-element(PurchaseOrder>

But their example set an option on the java command line in order to invoke the validation process.

After your comments, and more careful reading of the above web page, I notice that they're using Saxon 9SA also.

So, it appears that we can't do that now, but could do it if we were to obtain Saxon 9SA.

Thanks for your reply.

-- Mike
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Validating XML files during a transformation

Post by sorin_ristache »

mlcook wrote:I had seen this web page:
http://www.ibm.com/developerworks/xml/l ... axslt.html
which uses
<xsl:import-schema schema-location="po1.xsd"/>
and then
<xsl:template match="document-node(schema-element(PurchaseOrder>

But their example set an option on the java command line in order to invoke the validation process.

After your comments, and more careful reading of the above web page, I notice that they're using Saxon 9SA also.
Yes, you need a schema aware XSLT 2.0 processor for using xsl:import-schema, document-node(), schema-element(), etc.


Regards,
Sorin
Post Reply