Re: [xsl] Managing Generation of Output Filenames

Subject: Re: [xsl] Managing Generation of Output Filenames
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 7 Feb 2002 15:52:48 +0000
Hi Eliot,

> The challenge we're running into is we'd like to have a single chunk
> of code for generating the filenames, which have to go into both
> xsl:document tags and into hrefs used to create navigation links and
> authored cross references. We can't see any way to do this in XSL
> without writing an extension function.

What's wrong with making a single template, like:

<xsl:template name="generateFilename">
  ...
</xsl:template>

And then whenever you need the filename, put it in a variable:

  <xsl:variable name="filename">
    <xsl:call-template name="generateFilename" />
  </xsl:variable>

And then use the value of that variable in the href attribute using
attribute value templates:

  <a href="{$filename}">...</a>
  <xsl:document href="{$filename}">
    ...
  </xsl:document>

---

Or, since you're not using XSLT 1.0 anyway, why not move to XSLT 2.0
(Saxon 7.0) where you don't need to be so concerned about writing
extension functions, since they're all written in XSLT anyway. Just
write the filename-generating code in an xsl:function declaration:

<xsl:function name="my:generateFilename">
  ...
</xsl:function>

And call the function from the two attribute value templates:

  <a href="{my:generateFilename()}">...</a>
  <xsl:result-document href="{my:generateFilename()}">
    ...
  </xsl:result-document>

[If possible it'd be more efficient to go through a shared variable;
I'm just demonstrating that you don't have to.]

Am I missing some complication?
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread