Subject: Re: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] In XPath 2.0 can my XSLT , G. Ken Holman | Thread | Re: [xsl] In XPath 2.0 can my XSLT , Michael Kay |
RE: [xsl] In XPath 2.0 can my XSLT , G. Ken Holman | Date | Re: [xsl] In XPath 2.0 can my XSLT , Michael Kay |
Month |