Serially referring to elements in multiple files

Here should go questions about transforming XML with XSLT and FOP.
Sinai
Posts: 3
Joined: Mon Aug 12, 2013 6:39 pm

Serially referring to elements in multiple files

Post by Sinai »

Hello all,
I am trying to create an XSLT stylesheet in order to convert XML information from multiple files. I have used the collection function to group the files, but my problem is more complex:
I have two sets of files: one directory includes xml HEADERs, the other directory the xml TEXTs of the same documents. The TEXTs are grouped by the collection function and I extract the elements I require from it. In addition, I need to extract elements (title and date) from the parallel header file (which have the same name and a common ID element, only .hdr extension). I tried this way, which as I suspected did not work:

Code: Select all

<xsl:variable name="X" select="collection('file:/.../?select=*.xml;recurse=yes')//TEXT"/>
<xsl:for-each select="$X">
<tr>
<xsl:variable name="headerfile" select= "self::IDG/@ID"> </xsl:variable>

<td><xsl:value-of select="$headerfile"/></td>

<td><xsl:value-of select="doc('file:/.../$headerfile.hdr')//TITLESTMT/TITLE"/></td>
<td><xsl:value-of select="doc('file:/...//$headerfile.hdr')//SOURCEDESC//DATE"/></td>
<td><xsl:value-of select="TEXT/FRONT"/></td>
<td><xsl:value-of select="TEXT/BACK"/></td>
<td><xsl:value-of select="TEXT/BODY"/></td>
any ideas how else I could solve this?
Many thanks,
Sinai
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Serially referring to elements in multiple files

Post by adrian »

Hi,

The problem is you're not referring the headerfile variable correctly. This is not a macro, it won't be expanded if you refer it in the middle of a string. Try using the concat function when concatenating the file URI:
http://www.w3schools.com/xpath/xpath_fu ... asp#string

E.g.

Code: Select all

doc(concat('file:/.../’, $headerfile, '.hdr'))...
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Sinai
Posts: 3
Joined: Mon Aug 12, 2013 6:39 pm

Re: Serially referring to elements in multiple files

Post by Sinai »

Wow you're quick! thanks a lot!!!
Sinai
Posts: 3
Joined: Mon Aug 12, 2013 6:39 pm

Re: Serially referring to elements in multiple files

Post by Sinai »

:( alas, it does not work:

FODC0002: I/O error reported by XML parser processing file:/Users/Sinai/Dropbox/EEBO-TCP//.hdr: /Users/Sinai/Dropbox/EEBO-TCP/.hdr (No such file or directory)

it seems to have ignored the $headerfile variable all together. perhaps concatenation doesn't enable to include variables?
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Serially referring to elements in multiple files

Post by adrian »

Hi,

It's not ignoring it, but it's probably empty.

Code: Select all

<xsl:variable name="headerfile" select= "self::IDG/@ID"> </xsl:variable>
<td><xsl:value-of select="$headerfile"/></td>
What value do you see in the output between the td tags (the xsl:value-of seen above)?
If you see just <td></td>, then headerfile variable is empty, so you should check if the XPath (self::IDG/@ID) matches something on your input XML file in that context.

If you never get to see the output use: <xsl:message select="$headerfile"/> and you'll see the value in the Messages panel in Oxygen.

You can also use the debugger in Oxygen for such issues (Window > Open perspective > XSLT Debugger).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply