<node>{908-87238912-89732}</node> And I want to make this node part of a querystring, eg:
<a>
<xsl:attribute name="href">
<xsl:text>test.asp?id=</xsl:text>
<xsl:value-of select="node"/>
</xsl:attribute>
link
</a>
but this would result in
<a href="test.asp?id={908-87238912-89732}">link</a>
but what I really want is
<a href="test.asp?id=%7B908%2D87238912%2D89732%7D">link</a>
I can't find a function that can do this in XSLT, in ASP you'd use Server.URLencode(string) and in Client JScript escape(string). I read (never used it) that SAXON does this automatically - I think it must escape the whole href attribute though.
I could of course have some javascript do it all on the client though I'd like to avoid this.
The easiest way is to encode in in the XML. Thus:
<node>%7B908%2D87238912%2D89732%7D</node>
But if that isn't possible, the MSXML parser has a way of running JavaScript as it parses the file. I can't look it up right now, but if you can't find in the MSXML parser docs, send me a sticky and I'll try to help you out.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mydomain.com/myname">
<msxsl:script language="JScript" implements-prefix="user">
function uriencode(string) {
return escape(string);
}
</msxsl:script>
<xsl:template match="/">
<xsl:variable name="test" select="'h kjs lskdf'"/>
<xsl:value-of select="user:uriencode($test)"/>
</xsl:template>
</xsl:stylesheet>
eg:
<xsl:value-of select="user:uriencode(string(xpath/xpath/xpath))"/>
OR
<xsl:variable name="myvariable" select="string(xpath/xpath/xpath)"/>
<xsl:value-of select="user:uriencode($myvariable)"/>
<added>Just though - I didn't try converting to a string inside the function, I'll try that tomorrow;)</added>