dynamic URL

Here should go questions about transforming XML with XSLT and FOP.
coupes
Posts: 12
Joined: Tue Jun 14, 2005 6:40 pm

dynamic URL

Post by coupes »

Hi, I'm having a bit of an issue here... Basically, what I want to do is to dynamically generate the path where my output files will be created.

I have the following xml file :

Code: Select all


...

<file>
<filename name abv="dir1">Directory 1</name >
<file>
<filename abv="dir2">Directory 2</name >
<file>
<filename abv="dir3">Directory 3</name >
</file>
</file>
</file>

...
What I tried to do is to create a variable with the correct hierarchy (in that case : "/dir1/dir2/dir3") using concat() inside a for-each tag, but the result is a local variable. What I need is a global variable so I can use it to determine where my output files will go.

Code: Select all


...

<xsl:for-each select="//file">
<xsl:variable name="currentFile" select="concat('/',filename/@abv)"/>
<xsl:variable name="Path" select="$currentFile"/>
</xsl:for-each>

...
Any help would be greatly appreciated.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Having as input:

Code: Select all


<file>
<filename abv="dir1">Directory 1</filename>
<file>
<filename abv="dir2">Directory 2</filename>
<file>
<filename abv="dir3">Directory 3</filename>
</file>
</file>
</file>
the following stylesheet

Code: Select all


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="path">
<xsl:for-each select="//file">
<xsl:text>/</xsl:text>
<xsl:value-of select="filename"/>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$path"/>
</xsl:template>
</xsl:stylesheet>
will give you

Code: Select all


/Directory 1/Directory 2/Directory 3
Best Regards,
George
coupes
Posts: 12
Joined: Tue Jun 14, 2005 6:40 pm

Post by coupes »

Hey, that's pretty clever... :wink:

Thanks
Post Reply