[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] xslt document function - recursive folder processing.
Subject: Re: [xsl] xslt document function - recursive folder processing. From: Lighton Phiri <lighton.phiri@xxxxxxxxx> Date: Sat, 6 Aug 2011 15:25:40 +0200 |
Hi Abel, thank you very much. Question#1: How can I keep track of the folder attribute in the parent template (a). If I get what you mean, then this would effectively only work with the parent nodes accessing child parameters; what I want to do however is to access parent attributes in child nodes. (b). If that is possible, do you suppose it would be feasible to use this approach for a 3/4-level hierarchy of folders? Question# 2: What I meant to say in question 2 is: Is it possible to use the file://D| syntax with relative path names? It seems not to work and I was thinking that perhaps I could have been doing something wrong; my implementation requires the use of relative pathnames --for now. On 6 August 2011 14:34, Abel Braaksma <abel.online@xxxxxxxxx> wrote: >> 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: [xsl] 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. > > -- ------------------------------ Lighton Phiri http://lightonphiri.org/ ------------------------------
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt document function - , Abel Braaksma | Thread | Re: [xsl] xslt document function - , Abel Braaksma |
Re: [xsl] xslt document function - , Abel Braaksma | Date | [xsl] transforming MRSS, Dirk |
Month |