i want to display a link in xslt table that contient frensh special charactres:
the link is dynamic composed from : https://website.com/sites/the_name_of_attachment_in_xml
the xslt link:
<a><xsl:attribute name="href">https://website.com/sites/<xsl:value-of select="Attachments" disable-output-escaping="yes"/></xsl:attribute>
<xsl:value-of select="Attachments" disable-output-escaping="yes"/>
</a>
the html result is:
<a href="https://website.com/sites/ExampleName.pdf">ExampleName.pdf</a>
the issue is when the introduced name contient special charactere
for example : pré
sentation,
the link will be:
<a href="https://website.com/sites/Pr&#233;sentation.pdf">Présentation.pdf</a>
the "é"
charactere in the link is replaced by "&#233;"
i used disable-output-escaping="yes
to display correct charactere it worked just for
<xsl:value-of select="Attachments" disable-output-escaping="yes"/>
but didn't work in href attribute, i see other solution that tell to change in xslt code the
<xsl:output method="html" />
to <xsl:output method="xhtml" />
, but it didn't work form me i get error.
the result i want is:
<a href="https://website.com/sites/Présentation.pdf">Présentation.pdf</a>
How can i display the correcte link with special charactere using xslt?
this is xslt code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<table id="tableRepeat" border="1" width="100%" style="border-collapse:collapse;color:black;font-size:100%;font-family:arial,helvetica,sans-serif;">
<thead>
<tr>
<td>Attachments</td>
</tr>
</thead>
<tbody>
<xsl:for-each select="//Items/Item">
<tr>
<td>
<!-- this is how i display my link -->
<a>
<xsl:attribute name="href">https://website.com/sites/<xsl:value-of select="Attachments" disable-output-escaping="yes"/>
</xsl:attribute>
<xsl:value-of select="Attachments" disable-output-escaping="yes"/>
</a>
<!-- end: this is how i display my link -->
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
CodePudding user response:
This is because you are producing HTML output. There are serialization rules for the @href
.
If you remove the disable-output-escaping="yes"
and allow it to serialize, it produces:
<a href="https://website.com/sites/Présentation.pdf">Présentation.pdf</a>
That's a URLEncoded value, that if you decode, produces: https://website.com/sites/Présentation.pdf
.
Browsers know how to read it. Why are you concerned with how the value is serialized in the HTML source?
CodePudding user response:
because i didn't get the right url, it shows me page not found with this
equestUrl=https://website.com/sites/training/Lists/.../pr&
pr&
it stop here