XSLT why is & # xA; appears in my hrefs?

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:copy> <html> <body> <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 </a> <br/> </xsl:for-each> </body> </html> </xsl:copy> </xsl:template> </xsl:stylesheet> 

The result has the following:

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

Why do &#xA; and all the spaces? I am new to XSLT and my google searches haven’t changed anything that I understood. Thanks Sean

+6
xml xslt
source share
5 answers

Just use :

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

This (using AVT - attribute-value-patterns) is shorter and more readable.

The reason for the behavior message , as explained in almost all of the answers, is that the value of the href attribute is created (partially) from a text node containing the NL character.

Such problems are the result of a purely human psychological phenomenon : we clearly see NL when it is surrounded by non-white space, however we are NL-blind when NL is at the beginning or at the end of a block of text. It would be a useful feature of any XSLT / XML IDE to display query groups of special "invisible" characters, such as NL and CR.

+6
source share

&#A; is a coded newline character.

This and spaces are saved from newlines and spaces in your XSLT.

+5
source share

Spaces are preserved when mixing text and element nodes. So one solution is to avoid spaces to start (as shown by Bart) or to do the following, which may be more readable, as it is well formatted:

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

I'm also not very familiar with XSLT, but as you might 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 > 

to

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

The number of spaces in the output corresponds exactly to the number of spaces before http... in xslt. Delete those and the new line, and everything will be fine.

+1
source share

All Articles