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

Re: document() function and error-handling

Subject: Re: document() function and error-handling
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 3 Jan 2008 09:11:11 -0800
Re:  document() function and error-handling
> I've played around with some different scenarios in the stylesheet, and the error occurs any time I try to access the variable that contains the result of the document() function, even if I only want to check if it's non-empty. Is there any more graceful way (for MSXML, in particular) to handle the case where the URI passed to document() doesn't exist?

Bad luck ...


This is what the XSLT 1.0 Recommendation says:

"If there is an error retrieving the resource, then the XSLT processor
may signal an error; if it does not signal an error, it must recover
by returning an empty node-set."

So, signalling an error is exactly per spec.


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Jan 3, 2008 8:49 AM, Scott Trenda <Scott.Trenda@xxxxxxxx> wrote:
> Quick question, might be specific to the MSXML XSLT processor.
>
> I'm trying to reference two different files passed in as parameters to a transformation using the document() function. If the files are blank or valid URIs (the URI handling is correct), the transformation works as expected, but if the URI points to a non-existant file, MSXML errors out with code 0x800c0006: "The system cannot locate the object specified." I'm developing a central framework for several different applications, and I don't know if the application is actually going to create the file I'm trying to reference here. If it doesn't exist, I don't care, I just want to use it in the case that it does exist.
>
> I've played around with some different scenarios in the stylesheet, and the error occurs any time I try to access the variable that contains the result of the document() function, even if I only want to check if it's non-empty. Is there any more graceful way (for MSXML, in particular) to handle the case where the URI passed to document() doesn't exist?
>
> I've included the stylesheet I'm using at the bottom, just in case it helps.
>
> ~ Scott
>
>
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" exclude-result-prefixes="encodingStyle">
>
>  <xsl:param name="framework-map-file"/>
>  <xsl:param name="app-map-file" />
>
>  <xsl:output method="text" encoding="utf-8"/>
>
>  <xsl:variable name="framework-maps" select="document($framework-map-file)"/>
>  <xsl:variable name="app-maps" select="document($app-map-file )"/>
>  <xsl:variable name="maps" select="$framework-maps/*/map | $app-maps/*/map"/>
>
>  <xsl:template match="*">
>  <xsl:variable name="var-name">
>  <xsl:apply-templates select="." mode="name"/>
>  </xsl:variable>
>  <xsl:for-each select="$maps[normalize-space(@new) = $var-name]">
>  <xsl:value-of select="concat('&lt;webSet #', normalize-space(@old), '# = #', $var-name, '#&gt;&#10;')"/>
>  </xsl:for-each>
>  <xsl:apply-templates select="*"/>
>  </xsl:template>
>
>  <xsl:template match="*" mode="name">
>  <xsl:apply-templates select="parent::*" mode="name"/>
>  <xsl:choose>
>  <xsl:when test="../@encodingStyle:arrayType">[<xsl:number/>]</xsl:when>
>  <xsl:otherwise>
>  <xsl:if test="parent::*">.</xsl:if>
>  <xsl:value-of select="name()"/>
>  </xsl:otherwise>
>  </xsl:choose>
>  </xsl:template>
>
> </xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.