XSLT entity problem in attribute

Status
Not open for further replies.

Bloody Viking

Usenet Archive
Joined
Dec 15, 2004
Messages
8
Reaction score
0
Namaste, Y'all!

I've got a problem I'm hoping one of you can solve. My stylesheet has the following bit of code:

<xsl:template match="web|WEB">
<xsl:variable name="url">
<xsl:value-of select='translate(.," &#x9;&#xa;&#xd;", "")'/> </xsl:variable> <a><xsl:attribute name="href"><xsl:if test="not(starts-with($url,'http'))">http:&#47;&#47;</xsl:if><xsl:value-of select="$url"/></xsl:attribute> <xsl:value-of select="$url"/> </a> </xsl:template>

Given the following XML:

<othinfo>
<italic>New York Times</italic>, (Available at <WEB
URL="http:&#47;&#47;www.mat.
jhu.edu&#47;&#8764;sormani&#47;affirm-impact.html">http:&#47;&#47;www.mat.jhu.ed u&#47;&#8764;sormani&#47;affirm-impact.html</WEB>)
</othinfo>

the resultant HTML is:
<em>New York Times</em>, (Available at <a
href="http://www.mat.jhu.edu/%E2%88%BC
sormani/affirm-impact.html">http://www.mat.jhu.edu/&sim;sormani/affirm-impact.ht ml</a>)

As you can see, &#8764; is correctly translated to &sim; in the text part of the resultant <a> element, but is for some reason translated to %E2%88%BC in the href attribute. If I remove the translate function, and just have <xsl:variable name="url"><xsl:value-of select='.'/></xsl:variable> the result is identical.

- Paul Lieberman
 

Peter Flynn

Usenet Archive
Joined
Jan 2, 2000
Messages
1,813
Reaction score
0
Bloody Viking wrote:
Namaste, Y'all!

I've got a problem I'm hoping one of you can solve. My stylesheet has the following bit of code:

<xsl:template match="web|WEB">
<xsl:variable name="url">
<xsl:value-of select='translate(.," &#x9;&#xa;&#xd;", "")'/> </xsl:variable>

OK, so you're squashing out all spaces, TABs, CRs, and LFs.

<a><xsl:attribute name="href"><xsl:if
test="not(starts-with($url,'http'))">http:&#47;&#47;</xsl:if><xsl:value-of select="$url"/></xsl:attribute> <xsl:value-of select="$url"/> </a> </xsl:template>

OK, except I'm not clear why two innocuous slashes have been given as numeric references. Makes no difference to the program, just makes it harder to read.

Given the following XML:

Is there a reason why some normal characters have been given as numeric references here as well?

<othinfo>
<italic>New York Times</italic>, (Available at <WEB
URL="http:&#47;&#47;www.mat.
jhu.edu&#47;&#8764;sormani&#47;affirm-impact.html">http:&#47;&#47;www.mat.jhu.ed u&#47;&#8764;sormani&#47;affirm-impact.html</WEB>)
</othinfo>

What is that 8764 doing there? It should be a tilde (&#x7E;).

the resultant HTML is:
<em>New York Times</em>, (Available at <a
href="http://www.mat.jhu.edu/%E2%88%BC
sormani/affirm-impact.html">http://www.mat.jhu.edu/&sim;sormani/affirm-impact.ht ml</a>)

As you can see, &#8764; is correctly translated to &sim; in the text

Yes, but a &sim; is not what you want. You want a tilde there. A sim is a math graphic character and has no place in a URI.

part of the resultant <a> element, but is for some reason translated to %E2%88%BC in the href attribute.

That's because the 8764 shouldn't be there in the first place.

At a guess:

Your converter has re-encoded it as three bytes representing the Unicode for a sim character because you can't use Unicode characters in URIs (yet, wait until the Chinese proposal goes through :)

It didn't convert it in the text because Unicode might be allowed there, eventually (depending on the actual output encoding).

If I remove the translate function,
and just have
<xsl:variable name="url"><xsl:value-of select='.'/></xsl:variable> the result is identical.

No, get rid of the 8764 from the input: it's just bad data. Or translate it to a tilde character, which is correct. And maybe turn those 47s back into slashes to make it easier to check.

///Peter
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Bloody Viking wrote:
As you can see, &#8764; is correctly translated to &sim; in the text part of the resultant <a> element, but is for some reason translated to %E2%88%BC in the href attribute.

This is what the HTML output method is supposed to do. The XSLT 1.0 spec says:

The html output method should escape non-ASCII characters in URI attribute values using the method recommended in Section B.2.1 of the HTML 4.0 Recommendation.

This should not be a problem for you: it represents the same character. URIs are not allowed to contain non-ASCII characters, and a web browser would do this translation itself if it were not already done in the HTML.

-- Richard
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Peter Flynn wrote:
Your converter has re-encoded it as three bytes representing the Unicode for a sim character because you can't use Unicode characters in URIs (yet, wait until the Chinese proposal goes through :)

No need to wait for a Chinese proposal, we already have IRIs:

http://www.ietf.org/rfc/rfc3987.txt

-- Richard
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,051
Messages
3,104,251
Members
248,135
Latest member
tobystanx

Latest Threads

Top