RE: [xsl] Accessing the XML file name from an XSL Transform

Subject: RE: [xsl] Accessing the XML file name from an XSL Transform
From: Neil Owens <neil_owens@xxxxxxxxxxx>
Date: Mon, 15 Nov 2010 18:10:57 +0000
> Try the document-uri() function.
>
> Michael Kay
> Saxonica
>


Ok. I'm missing a little bit more, I'm afraid. I think this is to do with
variable scope, but I'm stood ready to be corrected.

I''ve got this:-

8<----------------
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes" name="TextFormat"
omit-xml-declaration="yes"/>
<xsl:param name="OutputPath" />
<xsl:variable name="FileFullPathName" select="document-uri(/)"/>
<xsl:variable name="FileName" />

<xsl:template match="/hello-world">
<xsl:analyze-string select="$FileFullPathName"
regex="[^/]+$">
<xsl:matching-substring>
<xsl:variable name="FileName" select="." />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>

<xsl:template match="mosLog">
<xsl:variable name="Command" select="concat('file:///', $OutputPath,
$FileName, '\Command-output.xml')" />
<xsl:result-document method="xml" href="{$Command}"
omit-xml-declaration="yes">
<xsl:apply-templates select="Command"/>
etc
etc
etc
8<---------------------------


but it's not right, as I've not figured out how to set 'FileName' as a global
variable, I'm assuming?  I want to be able to use the $FileName variable in
any Template in the XSLT transform.  Perhaps I don't need the analyze-string
template and could do it all in the variable declaration at the top, but I
couldn't find a suitable example to plagiarize, sorry, learn from.

Could anyone show me the 'proper' way to go about this?

Current Thread