this is a german Web-Mirror of MHONARC.ORG powered by Domainunion AG

[Top] [All Lists]

Re: [xsl] In XPath 2.0 can my XSLT program validate the input and check whether the validation succeeded?

2013-07-20 16:36:49
You can't do it in XPath but you can do it in XSLT:

<xsl:copy-of select="." validation="strict">

Michael Kay

On 20 Jul 2013, at 20:50, Costello, Roger L. wrote:

Hi Folks,

I want my input XML document to be validated within my XSLT program. 

I don't want the input validated when I invoke the transformation; thus, I do 
not specify the -val flag when I invoke SAXON.

I want to validate non-atomic values (i.e., elements with complexType).

I want to test whether the validation succeeded. 

I want to do this in XPath 2.0.

Is it possible?


I have an XML Schema which declares a Book element and a BookType:
   <xsd:element name="Book" type="BookType" />

   <xsd:complexType name="BookType">

In my XSLT program I import the XML Schema:

   <xsl:import-schema schema-location="BookStore.xsd"/>

In my XSLT program I have a template rule for Book. I want this template rule 
to validate the Book against the XML Schema and only output the Book if 
validation succeeds. Here is the code that I used:

   <xsl:template match="Book">
       <xsl:if test="data(.) instance of element(Book, BookType)">
           <xsl:sequence select="."/>

I ran my XSLT program and the output contained no Book elements, even though 
I know they are valid.

Here is what I think the problem is: since I did not specify the SAXON -val 
flag, the input has no type annotations. Consequently, each Book is not an 
instance of a Book element with type BookType and this boolean condition 

      data(.) instance of element(Book, BookType)

Do I have a correct understanding of what the problem is?

Is there a way to solve this problem? Here is what I seek: (1) don't validate 
the input at invoke time, (2) do validate the input within the XSLT program, 
and (3) do explicitly check whether validation succeeded.


XSL-List info and archive:
To unsubscribe, go to:
or e-mail: 

XSL-List info and archive:
To unsubscribe, go to:
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>