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

Here should go questions about transforming XML with XSLT and FOP.
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

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

Post 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?
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

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

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

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

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply