XSLT: Convert commercial at to its character entity

A

Anonymous

If I set as output method to HTML, it does what I want.

<html>
<body>
<p>
<a href="mailto:[email protected]">John Doe</a>
</p>
</body>
</html>

If I set it to XHTML, it doesn't but I need to generate XHTML.

<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<p>
<a href="mailto:john_doe&amp;#64;example.com">John Doe</a>
</p>
</body>
</html>

Using Xalan/J 2.5.2 for transformation if it matters...



people.xml
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<people>
<person id="john">
<name>John Doe</name>
<email>[email protected]</email>
</person>
</people>


people.xsl
----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="application/xml"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="xhtml"/> <!-- CHANGE HERE TO HTML -->

<xsl:template match="people">
<html>
<body>
<xsl:apply-templates select="person"/>
</body>
</html>
</xsl:template>

<xsl:template match="person">
<xsl:variable name="protocol" select="'mailto'"/>
<xsl:variable name="username" select="substring-before(email,'@')"/>
<xsl:variable name="hostname" select="substring-after(email,'@')"/>

<p>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$protocol"/>:<xsl:value-of
select="$username"/>
<!-- original try
<xsl:text>&amp;</xsl:text><xsl:text>#64;</xsl:text>
-->
<xsl:text disable-output-escaping="yes">
<![CDATA[@]]>
</xsl:text>
<xsl:value-of select="$hostname"/>
</xsl:attribute>
<xsl:value-of select="name"/>
</a>
</p>
</xsl:template>

</xsl:stylesheet>
 
D

Dean Tiegs

Anonymous said:
If I set as output method to HTML, it does what I want.

<html>
<body>
<p>
<a href="mailto:[email protected]">John Doe</a>
</p>
</body>
</html>

If I set it to XHTML, it doesn't but I need to generate XHTML.

<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<p>
<a href="mailto:john_doe&amp;#64;example.com">John Doe</a>
</p>
</body>
</html>

Why do you want to? <a href="mailto:[email protected]">John
Doe</a> is perfectly correct in both HTML and XHTML. The commercial at
sign does not have to be an entity reference.
 
A

Anonymous

Dean Tiegs said:
Why do you want to? <a href="mailto:[email protected]">John
Doe</a> is perfectly correct in both HTML and XHTML. The commercial
at sign does not have to be an entity reference.

Ever heard of email harvesting? Page(s) would be on very public
site and we get enough SPAM as is. Obfuscating email addresses
by character entity conversion is an effective means of hiding in
plain sight.
 

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
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top