Search code examples
xsltescapingcharacterhref

URL encoding with XSLT 1.0


I have a problem writing my XSL. I have a link with the following code:

<a>
<xsl:attribute name="href">
  <xsl:value-of select="concat($myUrl,'&amp;projectNumber=',$projectNumber)"/>
</xsl:attribute>
<xsl:attribute name="title">
  <xsl:value-of select="title"/>
</xsl:attribute>
LINK
</a>

So I need to pass a variable projectNumber to the end of myUrl. This works just fine and I get ...myUrl...&projectNumber=...projectNumber... in HTML.

The problem is, that the variable projectNumber sometimes has some characters which have to be escaped in the href of my link. I tried using the XSL function str:escape-uri() in many different ways, but still no success...

For example if myUrl is www.example.com/example.aspx?a=b and projectNumber is aaaūaaa I get href like www.example.com/example.aspx?a=b&projectNumber=aaaūaaa, but I need to get www.example.com/example.aspx?a=b&projectNumber=aaa%C5%ABaaa. (%C5%AB is the way that 'ū' is escaped) Any suggestions? Thanks.


Solution

  • If you are using XSLT 1.0, then refer this.

    In case of XSLT 2.0, you may use this to solve the issue.

    <xsl:value-of select="concat($myUrl,'&amp;projectNumber=',encode-for-uri($projectNumber))"/>