XSLT: Convert commercial at to its character entity

Discussion in 'XML' started by Anonymous, Mar 5, 2004.

  1. Anonymous

    Anonymous Guest

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

    <html>
    <body>
    <p>
    <a href="mailto:">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>
    </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>
    Anonymous, Mar 5, 2004
    #1
    1. Advertising

  2. Anonymous

    Dean Tiegs Guest

    Anonymous <> writes:

    > If I set as output method to HTML, it does what I want.
    >
    > <html>
    > <body>
    > <p>
    > <a href="mailto:">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:">John
    Doe</a> is perfectly correct in both HTML and XHTML. The commercial at
    sign does not have to be an entity reference.

    --
    Dean Tiegs, NE¼-20-52-25-W4
    “Confortare et esto robustusâ€
    http://telusplanet.net/public/dctiegs/
    Dean Tiegs, Mar 6, 2004
    #2
    1. Advertising

  3. Anonymous

    Anonymous Guest

    In article <>,
    Dean Tiegs <> wrote:

    > Anonymous <> writes:
    >
    > > If I set as output method to HTML, it does what I want.
    > >
    > > <html>
    > > <body>
    > > <p>
    > > <a href="mailto:">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:">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.
    Anonymous, Mar 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel van Laere

    Entity Name or Entity Number?

    Samuel van Laere, Feb 24, 2007, in forum: HTML
    Replies:
    4
    Views:
    1,599
    Jukka K. Korpela
    Feb 24, 2007
  2. markla
    Replies:
    1
    Views:
    533
    Steven Cheng
    Oct 6, 2008
  3. thunk
    Replies:
    1
    Views:
    294
    thunk
    Mar 30, 2010
  4. thunk
    Replies:
    0
    Views:
    458
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    606
    thunk
    Apr 3, 2010
Loading...

Share This Page