I am using XSLT 2 (Saxon HE 10.9).
I have the following directory tree:
Project
- index.xml
- Classes
- MyClassA
- MyClassA.xml
I am transforming MyClassA.xml
into a new file format.
Here a sample code:
<xsl:for-each select="properties/property[type = document('../../index.xml',.)/classes/class/id]">
<xsl:apply-templates select="display_name"/>
</xsl:for-each>
I'm getting the following error:
FODC0002 Exception thrown by URIResolver resolving `../../index.xml` against
`file:///D:/Project/Classes/MyClassA'. Found while atomizing the second operand of '='
I don't really understand why I'm getting this error, the path seems correct.
The path should be file:///D:/Project/Classes/MyClassA/../../index.xml
, which is the same as file:///D:/Project/index.xml
, and my file is indeed located here.
What am I doing wrong here?
EDIT: Here is the C# code that transform the file as asked in comments:
RawDestination destination = new RawDestination();
using (FileStream inputStream = File.OpenRead(inputFile))
{
XsltTransformer transformer = executable.Load();
using (MessageListener msg = new MessageListener(transformer))
{
msg.OnError = () => { success = false; };
transformer.BaseOutputUri = new Uri(outputFile);
transformer.SetInputStream(inputStream, new Uri(Path.GetDirectoryName(inputFile)));
transformer.Run(destination); // this will set HasError if an xsl:message contains "error:"
}
}
The code you have to set the base URI of the input stream to the directory of the input file is the culprit i.e. you have
transformer.SetInputStream(inputStream, new Uri(Path.GetDirectoryName(inputFile)));
but need
transformer.SetInputStream(inputStream, new Uri(inputFile));
If you set the base URI to the parent directory and then use a relative URI with ../../
you are ending up in file:/D:/
for your sample data.