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

Problems checking if document() exists or using docume

Subject: 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
xsl document exists
I have a master file called index.xml as follows:

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

@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
<monthly>
  <compounddef>
    <briefdescription>A description of name 1.</briefdescription>
    <other nodes...>
  </compounddef>
</monthly>

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="/">
        <html>
            <head>
                <title>Get descriptions from individual xml files</title>
                <!-- Use the @refid in index.xml to located file to add a descriptions for each.  -->
            </head>
            <body>
                <table>
                    <xsl:apply-templates select="index/compound"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="index/compound">
        <xsl:variable name="fName">
            <xsl:text>c:\MonthlyDataDump\xml\</xsl:text>
            <xsl:value-of select="@refid"/>
            <xsl:text>.xml</xsl:text>
        </xsl:variable>
        <tr>
            <td>
                <xsl:value-of select="name"/>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="...">
                        <xsl:apply-templates select="document($fName)//briefdescription"/>
                    </xsl:when>
                    <xsl:otherwise>
                      No description.
                      </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>
    <xsl:template match="monthly/compounddef/briefdescription">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Thanks
Karen

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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