xsl-list
[Top] [All Lists]

Re: [xsl] document() function and error-handling

2008-01-03 10:23:16


--------------------------------------------------
From: "Scott Trenda" <Scott(_dot_)Trenda(_at_)oati(_dot_)net>
Sent: Thursday, January 03, 2008 5:17 PM
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] document() function and error-handling

Robert -
Server-side transformation, so it's hitting the file system. You have a good idea there, but I couldn't configure the web server like that in the first place. (huge system, IT throws a fit if we ask for anything to be changed. you know how it is.)

Michael -
Wish I had an XSLT 2.0 processor available for regular use at work. :/ We've gone into this debate before, but I'm pretty much stuck with what's here, at least for now.


That said, does anyone know if MSXML provides a proprietary checking/handling function, or at least a workaround for this? I ask because I'm also trying to move a bunch of messy client-side XML.load() handling to server-side XSLT, but XML.load() handles invalid URIs gracefully, while document() does not. It'd be nice to be able to do the transformation in one pass, rather than having to do an intermediate transform simply to check the existance of the file URIs specified in the document source.

~ Scott


-----Original Message-----
From: Robert Koberg [mailto:rob(_at_)koberg(_dot_)com]
Sent: Thursday, January 03, 2008 11:07 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] document() function and error-handling


I will assume this is in a web environment. You could configure your web
app/server to return a well-formed error page when you get a 404 (and
disregard it if you want).

best,
-Rob

-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Sent: Thursday, January 03, 2008 11:05 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] document() function and error-handling

You're right, this question is specific to the processor. XSLT 1.0 makes it
implementation-defined what happens when you ask for a non-existent
document, and there's no mechanism in the standard for testing whether the
document exists or for recovering if it doesn't. XSLT 2.0 has a
doc-available() function for this purpose.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Scott Trenda [mailto:Scott(_dot_)Trenda(_at_)oati(_dot_)net]
Sent: 03 January 2008 16:49
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] document() function and error-handling

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>

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



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


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


Well you could always write your own doc-available() function using an msxsl:script element and the FileSystemObject.

Joe
http://joe.fawcett.name

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