xml – XSLT why is 
 showing up in my hrefs? – Education Career Blog

I have the following XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" omit-xml-declaration="yes" />
    <xsl:strip-space elements="*"/>
    <xsl:template match="@* | node()">

            <xsl:for-each select="AdvReqIMailMsg">

              <a><xsl:attribute name="href">
                  http://<xsl:value-of select="BackSideUrl"/>/customerlogin.asp?P=<xsl:value-of select="DynaCalPath"/></xsl:attribute >
                Login to View History of This Request

The result has the following:

<a href="&#xA;                  http://dotnet.dynacal.com/customerlogin.asp?P=DEMO8">
                Login to View History of This Request

Why are the &#xA; and all the spaces there? I am new to XSLT and my google searches haven’t turned anything up that I understood.


The &#A; is an encoded newline character.

It and the spaces are preserved from the newline and spaces in your XSLT.


Just use:

<a href="http://{BackSideUrl}/customerlogin.asp?P={DynaCalPath}">
           Login to View History of This Request

This (use of AVT — Attribute-Value-Templates) is both shorter and more readable.

The reason for the reported behavior, as explained in almost all answers, is that the value of the attribute href is constructed (partly) from text-node that contains the NL character.

Such issues are result from a purely human, psychological phenomenon: we clearly see the NL whenever it is surrounded by non-white-space, however we are NL-blind whenever the NL is at the start or at the end of a block of text. It would be a useful feature of any XSLT/XML IDE to show on request groups of special “invisible” characters, such as NL and CR.


The whitespace is preserved when you mix text and element nodes. So one solution is to avoid the whitespace to begin with (as shown by Bart), or to do the following, which may be more readable since it gets formatted well:

<xsl:attribute name="href">
    <xsl:value-of select="BackSideUrl"/>
    <xsl:value-of select="DynaCalPath"/>
</xsl:attribute >


I’m not really familiar with XSLT myself either, but as a guess from general programming experience, try changing

<xsl:attribute name="href">
                  http://<xsl:value-of select="BackSideUrl"/>/customerlogin.asp?P=<xsl:value-of select="DynaCalPath"/></xsl:attribute >


<xsl:attribute name="href">http://<xsl:value-of select="BackSideUrl"/>/customerlogin.asp?P=<xsl:value-of select="DynaCalPath"/></xsl:attribute >


The number of spaces in the output match exactly the number of spaces before http... in you xslt.
Remove those and the newline, and you should be fine.

Leave a Comment