Page 1 of 1

calling the document() function from within a for-each loop

Posted: Thu Sep 27, 2012 12:41 am
by sderrick
I need to process multiple documents, I have a list of filenames and am using a for-each loop to process the list

When inside the for-each, I can't use something like

Code: Select all


document(resolve-uri('build.log', document-uri(/)))
because document-uri(/) means nothing in the context of a for-each loop

I tried a relative path from the folder of the xslt stylesheet

Code: Select all


document('file:/../../working_files/build.log')
but it returns an empty-sequence()
I gave it the full path and it works

Code: Select all


document( 'file:///home/scott/workspace/mbel-work/working_files/build.log')
I can't use the full path as that path doesn't exist on the production server.

How can I get to the documents using a relative path?

Re: calling the document() function from within a for-each loop

Posted: Mon Oct 01, 2012 4:34 pm
by adrian
Hi,

The root(/) of the input XML document is still available in a for-each loop. So, I'm not sure why you say that:
document-uri(/) means nothing in the context of a for-each loop
I've tried the following xsl:messages inside a for-each loop and they worked fine:

Code: Select all

<xsl:message select="'URI:', document-uri(/)"/>
<xsl:message select="'Resolved URI:', resolve-uri('build.log', document-uri(/))"/>
<xsl:message select="'Doc:', document(resolve-uri('build.log', document-uri(/)))"/>
Where build.log contains just "<a/>".
My results are:

Code: Select all

[Saxon-PE] URI: file:/C:/Users/adrian/Desktop/Support/sample.xml
[Saxon-PE] Resolved URI: file:/C:/Users/adrian/Desktop/Support/build.log
[Saxon-PE] Doc:<a/>
Regards,
Adrian

Re: calling the document() function from within a for-each loop

Posted: Tue Oct 02, 2012 5:38 pm
by adrian
Hi again,

I had some doubts about more complicated for-each loops, so I've double checked and document-uri(/) changes as expected depending on the context from the for-each:

- if you have a for-each over a collection
e.g.

Code: Select all

<xsl:for-each select="collection('file:/C:/path/to/my/files/?select=*.xml;recurse=yes')">
- if you have a for-each over a sequence of documents.
e.g.

Code: Select all

<xsl:for-each select="document(('file:/C:/path/to/my/file.xml', 'file:/C:/other/path/to/my/other/file.xml'))">
So the question is, what kind of for-each are you using that's breaking this?

Regards,
Adrian