Posts

Showing posts from July, 2010

Encode URLs in XSL

Issue: You are updating a system which relies (too much?) on XSL-transformations to generate web content, and the system in question needs to be outfitted with URL encoding. Furthermore, you are using Microsoft's XSL-transformations (XslCompiledTransform) and hence are forced to use XSLT 1.0. Note: If you are using a system where XSLT v2.0 is available, there is a built-in function called url:encode() that you can use: <xsl:variable name="url-encoded-company-name" select="url:encode($company-name)"/> Oh, back to our problem at hand (or, rather, a solution): In the world of Microsoft and XSL, you can have the magic of JScript to help you out. This is how: Your XslCompiledTransform instances need to allow style sheets to execute scripts: //var transformer = new XslCompiledTransform(pathToFile); var settings = new XsltSettings( enableDocumentFunction: true, enableScript: true); var transformer = new XslCompiledTransform( pathToFile,