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

Handling type conversion errors

Subject: Handling type conversion errors
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Tue, 14 Oct 2003 14:02:48 -0600
xsl type conversion
Is there a standard way of handling type conversion errors in XPath 1.0/XSLT
1.0?  I understand that *most* data types can be implicitly cast to another
type, except to node-sets or RTFs.  But when a cast error *does* occur, how
should it be reported?

Consider the following stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="iso-8859-1"/>
  
  <xsl:template match="/">
    <vendors>
      <xsl:call-template name="build-vendor-list">
        <xsl:with-param name="preferred-vendors"/>
        <xsl:with-param name="nonpreferred-vendors"/>
      </xsl:call-template>
    </vendors>
  </xsl:template>
  
  <xsl:template name="build-vendor-list">
    <xsl:param name="preferred-vendors"/>
    <xsl:param name="nonpreferred-vendors"/>
    <preferred>
      <xsl:for-each select="$preferred-vendors/car-vendor">
        <vendor code="{@code}"><xsl:value-of select="."/></vendor>
      </xsl:for-each>
    </preferred>
    <nonpreferred>
      <xsl:for-each select="$nonpreferred-vendors/car-vendor">
        <vendor code="{@code}"><xsl:value-of select="."/></vendor>
      </xsl:for-each>
    </nonpreferred>
  </xsl:template>
</xsl:stylesheet>

You'll note that the call to build-vendor-list contains a critical error; I
don't set the value of the parameters passed to the template, so the
for-each loops attempt to iterate over what are essentially empty strings
(yes, I actually made this silly mistake, fortunately caught in QA).

Xalan (v2.5.1d at least) throws a ClassCastException and our presentation
service spits out a half-rendered page.  When Xalan encounters other
XSLT/XPath errors, it returns a message in addition to a stack trace; here
it just seems to barf.

Saxon 6.5.2 reports "The value is not a node-set," which is a lot more
useful.

Is this implementation-dependent?  Is the expectation that our presentation
service should catch and handle the exception?  Actually, this reveals
another question: shouldn't Xalan be testing for a valid node-set instead of
attempting a type conversion, since even implicit conversions to a node-set
aren't allowed?

thanks for the insight,
b.

| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.357.3548 |
| cheap tickets, part of trip network                fax 303.357.3380 |
| 6560 greenwood plaza blvd., suite 400           englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.