Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 383
Gintas K Avatar asked Jul 10 '13 11:07

Gintas K


People also ask

What is Number () in XSLT?

Specifies the format pattern. Here are some of the characters used in the formatting pattern: 0 (Digit) # (Digit, zero shows as absent)

What XSLT 3?

XSLT is used for transforming XML to XML (either according to a different data model, or by, for example, filtering some data), or into an HTML or text document. These transformations require an XSLT processor, which processes one or more XML documents with an XSLT stylesheet to produce an output document.

Can we use contains in XSLT?

contains() Function — Determines if the first argument string contains the second.


1 Answers

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))"/>
like image 147
Nidhin Joseph Avatar answered Oct 04 '22 21:10

Nidhin Joseph