Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, I have a bit of a paradox h

Status
Not open for further replies.

Crundy

Programmer
Jul 20, 2001
305
GB
Hello,
I have a bit of a paradox here. I'm trying to get my xslt template to output mailto links in encoded format (to stop spambots). This is how I've tried it:

<xsl:template match=&quot;emailwebmaster&quot;>
<a><xsl:attribute name=&quot;href&quot;>mailto:<xsl:text disable-output-escaping=&quot;yes&quot;>&amp;#119;&amp;#101;&amp;#98;&amp;#109;(etc)</xsl:text></xsl:attribute>
<xsl:text disable-output-escaping=&quot;yes&quot;>&amp;#119;&amp;#101;&amp;#98;&amp;#109;(etc)</xsl:text></a>
</xsl:template>

And strangely enough, the link text (between the <a> tags) works ok (looks like &#119;&#101;&#98;&#109; and so on) but the text in the href attribute still has the &amp; instead of just an ampersand.

I've tried encoding the 'mailto:' text as well with the same result.

Does anyone know why this is working in one place and not another?
C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
have you tried put the email: inside the text tag like this:

..
Code:
<xsl:text disable-output-escaping=&quot;yes&quot;>mailto:& #119;& #101;& #98;& #109;(etc)</xsl:text>
..

?
any linefeeds outside the tags will appear. On mine, i get this output cause I have a linefeed in my xsl after mailto:
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?><a href=&quot;mailto:& #xA;				mailto:webm(etc)&quot;>webm(etc)</a>

hope that helps.

matt
 
Hi Flumpy,
Sorry, I didn't see your message before I sent my correction.

Yes I've tried putting the mailto in unencoded format both within and outside the <xsl:text>, and all the code is on one line.

I just don't get why it works in one place in the code and not another! C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
yeeeees.

hmm.

see what you mean. try this instead:

Code:
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL]
version=&quot;1.0&quot;>
<xsl:template match=&quot;/&quot;>
  <html>
  <head><title>Link test</title></head>
  <body>

<xsl:variable name=&quot;enc&quot;><xsl:text disable-output-escaping=&quot;yes&quot;>& #109;& #97;& #105;& #108;& #116;& #111;& #58;& #97;</xsl:text></xsl:variable>
<xsl:element name=&quot;a&quot;>
<xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;$enc&quot;/></xsl:attribute>
<xsl:value-of select=&quot;$enc&quot;/>
</xsl:element>
	
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

that seems to work. no idea why it doesnt hte other way round, prolly a bug of somesort.

matt
 
Still no joy.

If I leave it as you suggested (removing the spaces) then it parses the characters so the output is in plain text, and if I change the ampersands to &_amp; (without the underscore) then it outputs them as they are and the link looks like this:
&_amp;#109;&_amp;#97;&_amp;#105;&_amp;#108;&_amp;#116;&_amp;#111;&_amp;#58;&_amp;#97;
C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
sorry, the code should be:

Code:
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL]
version=&quot;1.0&quot;>
<xsl:template match=&quot;/&quot;>
  <html>
  <head><title>Link test</title></head>
  <body>

<xsl:variable name=&quot;enc&quot;><xsl:text disable-output-escaping=&quot;yes&quot;>& #119;& #101;& #98;& #109;(etc)</xsl:text></xsl:variable>
<a>
<xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;$enc&quot;/></xsl:attribute>mailto:<xsl:value-of select=&quot;$enc&quot;/>
</a>
	
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

matt
 
But it's parsing the characters, so if I view the source of the output it comes out as:
<a href=&quot;webm(etc)&quot;>webm(etc)</a>

So it's not working as I need it to. The email address is unencoded in the source. C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
but then no one would be able to click on the link and mail you?

the source is the source, and you cant have one source but another display.. that wouldnt make sense!
 
On that page, the mailto link at the bottom is encoded, but it looks just the same as a plain text link. The user's browser parses the characters. C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
light dawns on marble head. (an interesting thing is that i couldnt see the source for my own document, but i could see yours)


this is bizarre, and possibly a feature of xsl parsing the text node into the href element's attribute field.


it looks like you can do it like this:
..
Code:
<a href=&quot;mailto:& #119;& #101;& #98;& #109;(etc)&quot;>
..

but then you couldnt dynamically use the nodes values in it.

ho hum. anyone else?

 
ps can you check my source code on the url i posted, just to see if that worked?

 
I did check it, and unfortunately the entities had been parsed by the xml parser.

This is a bit of a puzzle! I don't believe that there isn't a way of doing it. My first example shows that it does work, but not within certain tags (for some reason). C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
ok after reading


i think i've come to the conclusion that it is impossible. the parser will automatically try to convert escaped characters to real one when it needs to, and will only escape characters that are not ascii characters when the xsl:eek:utput is in type html.

reading this didnt help any with the problem, but it did give me a little insight into the way the parser behaves.

read this bit esp:
&quot;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.
16.4 Disabling Output Escaping&quot;


and section 16.4: &quot;Disabling Output Escaping&quot;

...

ho hum.
matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top