XSLT: Convert commercial at to its character entity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anonymous

    XSLT: Convert commercial at to its character entity

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

    <html>
    <body>
    <p>
    <a href="mailto:jo hn_doe&#64;exam ple.com">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:jo hn_doe&amp;#64; example.com">Jo hn 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>john_doe @example.com</email>
    </person>
    </people>


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

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

    <xsl:output 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="substri ng-before(email,'@ ')"/>
    <xsl:variable name="hostname" select="substri ng-after(email,'@' )"/>

    <p>
    <a>
    <xsl:attribut e name="href">
    <xsl:value-of select="$protoc ol"/>:<xsl:value-of
    select="$userna me"/>
    <!-- original try
    <xsl:text>&amp; </xsl:text><xsl:t ext>#64;</xsl:text>
    -->
    <xsl:text disable-output-escaping="yes">
    <![CDATA[&#64;]]>
    </xsl:text>
    <xsl:value-of select="$hostna me"/>
    </xsl:attribute>
    <xsl:value-of select="name"/>
    </a>
    </p>
    </xsl:template>

    </xsl:stylesheet>
  • Dean Tiegs

    #2
    Re: XSLT: Convert commercial at to its character entity

    Anonymous <inetladd@hotma il.com> writes:
    [color=blue]
    > If I set as output method to HTML, it does what I want.
    >
    > <html>
    > <body>
    > <p>
    > <a href="mailto:jo hn_doe&#64;exam ple.com">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:jo hn_doe&amp;#64; example.com">Jo hn Doe</a>
    > </p>
    > </body>
    > </html>[/color]

    Why do you want to? <a href="mailto:jo hn_doe@example. com">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”

    Comment

    Working...