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-15 14:42:04
   test="string(bk:ISBN) instance of bk:ISBN-type">

Thanks Ken, I see what you're saying.

I gave that a try (I replaced data with string). Unfortunately, I get the same 
error message.

/Roger

-----Original Message-----
From: G. Ken Holman [mailto:g(_dot_)ken(_dot_)holman(_at_)gmail(_dot_)com] On 
Behalf Of G. Ken Holman
Sent: Monday, July 15, 2013 3:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com; 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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?

At 2013-07-15 18:55 +0000, Costello, Roger L. wrote:
The item of interest, however, is this snippet:

            <xsl:for-each select="/bk:BookStore/bk:Book">
                <xsl:if test="data(bk:ISBN) instance of bk:ISBN-type">
                    <ISBN><xsl:value-of select="bk:ISBN"/></ISBN>
                </xsl:if>
            </xsl:for-each>

The for-loop iterates through each Book and checks to see if the 
value of its ISBN element conforms to ISBN-type; if it doesn't 
conform, then it skips that ISBN and goes to the next Book.

In the XML document shown above, the Book element has an ISBN 
(xxx1-56592-235-2) that is not valid, so I expect my XSLT program to skip it.

However, that is not happening. I get this error message:

    The content "xxx1-56592-235-2" of element <ISBN> does not
    match the required simple type. Value "xxx1-56592-235-2"
    contravenes the pattern facet "\d{1}-\d{5}-\d{3}-\d{1}|\d{1}-..."
    of the type ISBN-type

Yep!  Because I think you are taking one step too far.  I haven't 
tested it, but I think this will work for you:

    test="string(bk:ISBN) instance of bk:ISBN-type">

What am I doing wrong please?

You are enforcing the schema constraint by using data() before 
checking that the content conforms to the constraint.  In my code I'm 
simply getting the value as a string, thus not imposing any 
constrains, and then checking that string to be convertible to the 
said constraints.

Please let me know if that works for you.

I hope it helps.

. . . . . . . Ken

--
Public XSLT, XSL-FO, and UBL classes in the Netherlands     Oct 2013 |
Public XSLT, XSL-FO, UBL and code list classes in Australia Oct 2013 |
Contact us for world-wide XML consulting and instructor-led training |
Free 5-hour lecture: https://www.CraneSoftwrights.com/links/udemy.htm |
Crane Softwrights Ltd.            https://www.CraneSoftwrights.com/s/ |
G. Ken Holman                   mailto:gkholman(_at_)CraneSoftwrights(_dot_)com 
|
Google+ profile: https://plus.google.com/116832879756988317389/about |
Legal business disclaimers:    https://www.CraneSoftwrights.com/legal |


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


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