Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Mark Carlson <carlsonm@---------------->
To:
Date: 1/3/2008 10:06:00 PM
I ran into a similar problem where I have "placeholders" for links that 
should be created if the corresponding file exists but not if they 
don't.  I decided to put in these placeholders so that I wouldn't have 
to go back in and update ca. 3,000 files one by one with the linking 
information.  I currently only have access to MSXML XSLT parser 1.0 on 
the server so couldn't use doc-available function and MSXML doesn't 
support the "script" extension.  My hypothetical workaround will be to 
create a separate "link base" document that my link points to.  I will 
use XSLT 2.0 or another scripting language (JScript, VBScript, etc.) to 
generate an XML document that will determine which of the links are 
valid and which ones are not.  Thus my XSLT document will query the link 
base document rather than querying the file directly.  So your link 
could point to file "file1.xml" and you could have a "link base" version 
of that file on your server that could evaluate to true or false:



<?xml version="1.0"?>
<!-- This is file1.xml -->
<fileexists>true</fileexists>

Or you could have a list of valid links in one single XML document that 
only contains valid files that you could query:



<?xml version="1.0"?>
<!-- This is linkbase.xml -->
<document>
<validfile>file1.xml</validfile>
<validfile>file25.xml</validfile>
<validfile>file30.xml</validfile>
<validfile>file40.xml</validfile>
</document>

And then query that single file for whether it exists.



It's a bit of a hack, but if you are limited to MSXML 1.0, then it's a 
good workaround.



Mark Carlson
Computer Support Analyst
Special Collections Division
University of Washington Libraries
BOX 352900
Seattle, WA, 98195
(206) 543-1929
http://staff.washington.edu/carlsonm/


Scott Trenda 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>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent