[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: xslt document function - recursive folder processi
Subject: Re: xslt document function - recursive folder processing.
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Sat, 06 Aug 2011 14:34:53 +0200
|
This is my first post;
Welcome!
How can I keep track of the folder attribute in the parent template
You're challenge is that you start from a new document node, from that
point on, the original document node is out of scope. However,
xsl:apply-templates can have a child, xsl:with-param. Use
<xsl:with-param name="filename" select="@name" /> and inside the
matching template, add <xsl:param name="filename" />. You can then refer
to this by using the variable $filename.
The potion of code below fails until I explictly provide the absolute
path and also prepend it with file://D|
Not sure what the question is for Q #2, but your conclusion is correct.
You need to provide a URI. The exact syntax for a file-uri is often
debated and can be processor dependent (i.e., some may require file:///,
as after file:// for protocol, you must first provide the root /).
Is it possible for me to determine using XSLT the directory path of
the XML file being processed?
Certain processors may provide extension functions for that. In XSLT
2.0, you can use the base-uri() function to find the filename (not
quite: to find the base uri) of a document. You can even use
base-uri(documen('')) to get the filename of the executing XSLT file. If
you need to stick to XSLT 1.0, you can pass the filename as a parameter
on the commandline. Define the parameter as xsl:param in the root of
your styleseet. Same solution works for getting the absolute current
path (you Q #2).
Cheers,
Abel
------------------------------------------------------------------------
From: Lighton Phiri <lighton.phiri@xxxxxxxxx>
Sent: Saturday, August 06, 2011 12:34:26 PM
To: xsl-list
Cc:
Subject: xslt document function - recursive folder processing.
I am working with XSLT version 1.0 using xsltproc.
This is my first post; please bare with me if I've missed out on any
of the house rules. I have tried as much as possible to replicate what
I am trying to do below. My senario is as follows:
Folder Structure
folder/
|-- index.xml
|-- dir1
| |-- d1f1.xml
| |-- d1f2.xml
| |--
|-- dir2
| |-- d2f1.xml
| |-- d2f2.xml
| |--
Current XSLT stylesheet
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="folder">
<xsl:apply-templates select="document(file)/file" />
</xsl:template>
<xsl:template match="file">
<name>
<xsl:value-of select="name" />
</name>
<link>
<file>document(../dir2/d2f1.xml, /)/file/name</file>
<description>document(../dir2/d2f1.xml, /)/file/description</description>
</link>
</xsl:template>
</xsl:stylesheet>
index.xml file
<?xml version="1.0" encoding="utf-8"?>
<folder name="dir1">
<file>f1.xml</file>
<file>f2.xml</file>
</folder>
d1f1.xml
<?xml version="1.0" encoding="utf-8"?>
<file>
<name>File 1</name>
<description>I am file 1</description>
<link>dir2/d2f1.xml</link>
</file>
d2f2.xml
<?xml version="1.0" encoding="utf-8"?>
<file>
<name>File 2</name>
<description>I am file 2</description>
</file>
Question# 1:
How can I keep track of the folder attribute in the parent template so
I can make use of it when calling the child templates?
Question# 2:
The potion of code below fails until I explictly provide the absolute
path and also prepend it with file://D|
this fails
<link>
<file>document(../dir2/d2f1.xml, /)/file/name</file>
<description>document(../dir2/d2f1.xml, /)/file/description</description>
</link>
this works (I stole this idea from
http://www.dpawson.co.uk/xsl/sect2/N2602.html#d3862e403)
<link>
<file>document(file://D|/home/phiri/dir2/d2f1.xml)/file/name</file>
<description>document(file://D|/home/phiri/dir2/d2f1.xml)/file/description</description>
</link>
Question# 3:
Is it possible for me to determine using XSLT the directory path of
the XML file being processed?
All sources I have found online seem to suggest its not possible to
evaluate the directory path of the XML file being processed.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|