Re: [xsl] URI's, double backslashes and regular expressions

Subject: Re: [xsl] URI's, double backslashes and regular expressions
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 28 Oct 2010 23:30:11 +0100
On 28/10/2010 19:51, Neil Owens wrote:

I just can't figure out the syntax here


I'm passing a directory location into Saxon as a parameter. Only I need to make every '\' character in the (windows) directory path a '\\' for the uri in the transform. As it's only the transform that needs this I thought I'd do the conversion in the transform. And it's beaten me.

The href attribute of xsl:result-document expects a URI, not a Windows filename, and URIs always use forward slashes to separate components of the path.


Even if it were a backslash, the backslash is not a special character in XPath and does not need escaping.

Moreover: string concatenation is an unreliable way of constructing a URI from a base URI plus a relative reference. Much better to use the resolve-uri() function. (I'm afraid this is advice I don't always follow myself, but I often end up regretting it.)

Michael Kay
Saxonica
The command line param is: ...path="C:\Documents and Settings\Adminis
trator\My Documents\Projects\Transform\OutputFiles"

I've got this neatly passed into the transform with:

<xsl:param name="path"></xsl:param>
...
<xsl:template match="Log">
         <xsl:value-of select= replace($path, '\\', '\\')" />
         <xsl:variable name="Command" select="concat($path, '\\OutputFiles\\Command-output.xml')" />
         <xsl:result-document method="xml" href="{$Command}">
         .....


But fails and I just can't figure out how to achieve setting the result-document href to equal "C:\\Documents and Settings\\Administrator\\My Documents\\Projects\\Transform\OutputFiles"


I know I can (I tried and it works) just add the correct number of backslashes to the command line param, but I don't want to.

As ever, thanks in advance...

Current Thread