[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Problems checking if document() exists or using document() pointing to different directory

Subject: [xsl] Problems checking if document() exists or using document() pointing to different directory
From: "Karen Dunstall" <kdunstall@xxxxxxxxxxxxxxx>
Date: Fri, 9 Jan 2004 16:00:01 +1100

I have a master file called index.xml as follows:

  <compound @refid="name1">
    <name>a text name</name>
  <compound @refid="name2">
    <name>another name</name>

@refid refers to a file name, without a path or extension.

I also have a whole lot of other xml files in a different directory.  

e.g. c:\MonthlyDataDump\xml\name1.xml
    <briefdescription>A description of name 1.</briefdescription>
    <other nodes...>

My xsl is in a separated directory altogether, along with index.xml.

For each <compound> element in index.xml I need to get a description from the associated @refid file in the other directory.  I am using the document() command to do this.

This works well when I have:
a) all xml files and the stylesheet in the same directory, and
b) a data dump file for every record in index.xml.

Where I have problems is when I use documents in another directory and/or where there are missing referenced files.  I keep getting a "system cannot locate the oject specified" error.   It works fine if I put a text filenamewith, with path, into the document command.  I don't know if I have two errors -- one trying to reference documents in another directory, the other trying to access non-existing files, or just one of these, but the first thing I tried to do is test if the document exists.  Unfortunately, I'm not sure how to do this without actually using the document statement itself.

My stylesheet is as follows.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="/">
                <title>Get descriptions from individual xml files</title>
                <!-- Use the @refid in index.xml to located file to add a descriptions for each.  -->
                    <xsl:apply-templates select="index/compound"/>
    <xsl:template match="index/compound">
        <xsl:variable name="fName">
            <xsl:value-of select="@refid"/>
                <xsl:value-of select="name"/>
                    <xsl:when test="...">
                        <xsl:apply-templates select="document($fName)//briefdescription"/>
                      No description.
    <xsl:template match="monthly/compounddef/briefdescription">
        <xsl:value-of select="."/>


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

Current Thread