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