[xsl] document() function and error-handling

Subject: [xsl] document() function and error-handling
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Thu, 3 Jan 2008 10:49:07 -0600
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";

            <xsl:param name="framework-map-file"/>
            <xsl:param name="app-map-file"      />

            <xsl:output method="text" encoding="utf-8"/>

            <xsl:variable name="framework-maps"
            <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="."
                        <xsl:for-each select="$maps[normalize-space(@new) =
                                   <xsl:value-of select="concat('&lt;webSet
#', normalize-space(@old), '# = #', $var-name, '#&gt;&#10;')"/>
                        <xsl:apply-templates select="*"/>

            <xsl:template match="*" mode="name">
                        <xsl:apply-templates select="parent::*" mode="name"/>


Current Thread