XSL question-- walking a hierarchy

J

Jim Bancroft

Sorry for the basic nature of this question. I know XSL can do this, but I
don't recall a good method...

Say I have an xml structure like this:

<folder_structure>
<folder name="folder1">
<file name="myfile"/>
</folder>
<folder name="folder2">
</folder>
<folder name="folder3">
<file name="somefile"/>
<file name="anotherfile"/>
</folder>
<folder name="folder4">
<folder name="folder5">
<file name="newfile"/>
</folder>
</folder>
</folder_structure>


I need to use XSL to whip up a series of file paths, like this:

folder1\myfile
folder3\somefile
folder3\anotherfile
folder4\folder5\newfile

I'm having trouble with walking the subfolders; for instance, the
folder4\folder5 path above.

The file paths can be arbitrarily deep, and I'm stumped on how to create a
file <xsl:template> that recuruses up the tree and pulls all the parent
folder names. If you have any advice, I'd be grateful. Thanks.
 
J

Jim Bancroft

Thanks, Dimitre.

I'm still a little unclear on how I'm supposed to use your snippet-- do
I paste it whole into my XSL code somewhere, then pass my node into it?
 
D

Dimitre Novatchev

Jim Bancroft said:
Thanks, Dimitre.

I'm still a little unclear on how I'm supposed to use your snippet-- do
I paste it whole into my XSL code somewhere, then pass my node into it?

In the snippet there is:

<xsl:variable name="theParmNodes" select="//namespace::*[local-name() =
'myNamespace']"/>

This causes the code to produce XPath expressions for all namespace nodes
having prefix 'myNamespace'.

If you want to get the XPath expression for a specific node, it should be
specified as the "theParmNodes" xsl:param

Of coourse, it is best to group the snippet into a named template, so that
it can be called from different places simply with

<xsl:with-param name="theParmNodes" select="."/>

Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top