[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: In XPath 2.0 can my XSLT program validate the inpu

Subject: Re: In XPath 2.0 can my XSLT program validate the input and check whether the validation succeeded?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 20 Jul 2013 22:36:28 +0100
Re:  In XPath 2.0 can my XSLT program validate the inpu
You can't do it in XPath but you can do it in XSLT:

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

Michael Kay
Saxonica

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?
>
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.