OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Website+XSLT=source filename?


On Tue, Feb 22, 2005 at 09:50:15PM -0600, Thomas Jones wrote:
> How does one go about finding out the XML source filename in XSL?

<snip/>

> As you can see, I am having to generate a specific element to hold the source 
> filename. But, given the volume of pages that I am constructing(4,000+); I 
> would rather utilise a construct during transformation so that I don't need 
> to alter the XML sources and add this element.

I don't know if there's a way to access that information directly from
XSLT.  I think one reason for this missing native functionality is the
fact that XML documents do not always have filenames or URIs; for
example, a SOAP document may not have a URI but may be input into an
XSLT processor.  However, it would be easy (and, in my opinion, and elegant
solution) to pass that information into the stylesheet from the calling
process.  If the calling process is explicitly running an XSLT processor
on your filename, then obviously it knows the filename (and other
context, such as the current working directory) and can pass that
information into the stylesheet.  XSLT can accept parameters using the
xsl:param element, as follows:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <!-- any imports (for customization) would go here ... -->

  <xsl:param name="filename"/>

  <!-- a very simple example using the above parameter: -->

  <xsl:template match="/">
    <document filename="{$filename}"/>
  </xsl:template>
</xsl:stylesheet>

Then you would pass the filename into the stylesheet, for
example, using xsltproc:

  $ xsltproc --stringparam filename target.xml stylesheet.xsl target.xml
  <?xml version="1.0"?>
  <document filename="target.xml"/>

You can do what you like with the filename, and pass other pieces of
information in as necessary.

Take care,

    John L. Clark

PGP signature



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]