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

Subject: [xsl] In XPath 2.0 can my XSLT program validate the input and check whether the validation succeeded?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Sat, 20 Jul 2013 19:50:30 +0000
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?

EXAMPLE

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

    <xsd:complexType name="BookType">
        <xsd:sequence>
            ...
        </xsd:sequence>
    </xsd:complexType>
------------------------------------------------------------------

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="."/>
        </xsl:if>
    </xsl:template>

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
fails:

	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.

/Roger

Current Thread