Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT why is 
 showing up in my hrefs?

Tags:

xml

xslt

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 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. Thanks, Shawn

like image 244
Shawn Avatar asked Oct 19 '10 17:10

Shawn


People also ask

Why is XSLT used?

XSLT is used to transform XML documents into XHTML documents, or into other XML documents.

Is XSLT still relevant?

XSLT has become the language of choice for a very wide range of XML applications. It is of course still used to produce XSL-FO documents for printing, but it is also used to integrate back-end software for Web sites.

What is XSLT explain?

XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

What are the advantages of XSLT over CSS?

One advantage that XSLT provides over CSS is that while CSS can “decorate the tree,” XSLT can rearrange it, fetching nodes from one place in the input tree and writing them somewhere else in the output tree.


2 Answers

The &#A; is an encoded newline character.

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

like image 66
SLaks Avatar answered Oct 05 '22 14:10

SLaks


Just use:

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

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.

like image 28
Dimitre Novatchev Avatar answered Oct 05 '22 14:10

Dimitre Novatchev