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

xsl-list
[Top] [All Lists]

RE: [xsl] How to check an element's type against an XSD simpleType and skip that element if it does not conform to the simpleType?

2013-07-16 08:13:07
Michael Kay wrote:

you could read an (unvalidated) BOOKLIST and then iterate 
over the BOOK elements, validating each one in turn, catching 
any errors ... and then doing different processing based on 
whether the BOOK was valid or not.

I must not be understanding what you and David are suggesting. Below is an XSLT 
program which does (I think) what you guys are suggesting, but it still 
generates an error if the XML document has an ISBN element with a value that is 
not schema-valid. What is my XSLT program doing wrong?  /Roger

-----------------------------------------------------------------
   Check ISBN using "castable as"
-----------------------------------------------------------------
<xsl:transform xmlns:xsl="https://www.w3.org/1999/XSL/Transform";
               xmlns:bk="https://www.books.org";
               exclude-result-prefixes="bk"
               version="2.0">
 
    <xsl:output method="xml"/>

    <xsl:import-schema namespace="https://www.books.org";
        schema-location="BookStore.xsd"/>

    <xsl:template match="/">
        <BookISBNs>
            <xsl:for-each select="/bk:BookStore/bk:Book/bk:ISBN">
                <xsl:if test=". castable as bk:ISBN-type">
                    <ISBN><xsl:value-of select="."/></ISBN>
                </xsl:if>
            </xsl:for-each>
        </BookISBNs>
    </xsl:template>

</xsl:transform>

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Tuesday, July 16, 2013 8:56 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: Costello, Roger L.
Subject: Re: [xsl] How to check an element's type against an XSD simpleType and 
skip that element if it does not conform to the simpleType?


On 16 Jul 2013, at 13:29, David Carlisle wrote:

On 16/07/2013 13:07, Costello, Roger L. wrote:
Michael Kay wrote:

Unfortunately schema-aware processing in XQuery and XSLT doesn't
give you this capability.

Is there a workaround?

Is there is no way for an XSLT program to express: "Hey, validate xyz
against the XML Schema and if xyz is not schema-valid then discard
it." No way to express that?


Can't you just not validate the input, then test within the stylesheet
as you are testing an atomic/simple type.


Yes, in fact you could do it at a different granularity; you could read an 
(unvalidated) BOOKLIST and then iterate over the BOOK elements, validating each 
one in turn, catching any errors using try/catch, and then doing different 
processing based on whether the BOOK was valid or not.

Michael Kay
Saxonica

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


<Prev in Thread] Current Thread [Next in Thread>