Trying to write less_than symbol twice("<<") using XSLT. It doesn't work if I try writing it twice

189 views Asked by At

I don't know why, but whatever I try to write this string "<<" using XSLT, the parser gives me an error; I tried the same with writing greater_then symbol twice(">>") and it worked. These are the ways I tried to use:

1 - <xsl:text disable-output-escaping="yes">&lt;&lt;</xsl:text>
2 - <xsl:text disable-output-escaping="yes">&lt;&#60;</xsl:text>
3 - <xsl:text disable-output-escaping="yes">&#60;&#lt;</xsl:text>
4 - <xsl:text disable-output-escaping="yes">&#60;&#60;</xsl:text>
5 - <xsl:text disable-output-escaping="yes">&#lt;</xsl:text><xsl:text disable-output-escaping="yes">&#lt;</xsl:text>

...none of them work. Does someone of you know why? Thank you in advance.

EDIT: I tried using many parser through internet, like on the websites: altervista; w3c. The error I get is: "XML: non well-formed"

Even trying this little xslt code, it gives me the same error:

<?xml version="1.0" encoding="UTF-8"?>

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

    <xsl:template match="/logs">
        <html>
            <body>
                &lt;&lt;
            </body>
        </html>
    </xsl:template>

    </xsl:stylesheet>

But this works...:

<?xml version="1.0" encoding="UTF-8"?>

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

    <xsl:template match="/logs">
        <html>
            <body>
                &lt;
            </body>
        </html>
    </xsl:template>

    </xsl:stylesheet>
2

There are 2 answers

0
Martin Honnen On

XSLT code is XML and within XML you need to escape any < less-than symbol not to be used as markup as &lt; and consequently two of them as &lt;&lt; as you have done. In that case XML parsing and XSLT processing should work fine and does for me at http://xsltransform.net/bFDb2CP which simply has the input

<?xml version="1.0" encoding="UTF-8"?>
<logs/>

the XSLT code

<?xml version="1.0" encoding="UTF-8"?>

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

    <xsl:template match="/logs">
        <html>
            <body>
                &lt;&lt;
            </body>
        </html>
    </xsl:template>

    </xsl:stylesheet>

and the result

<html>
   <body>
      &lt;&lt;

   </body>
</html>

If your test environment gives you an error on &lt;&lt; then it is broken and not a usable environment to learn, test, run or debug XSLT code.

0
Ian Roberts On

When you say "none of them work" it depends what you mean by "work". Any of the five approaches you have given in the question should correctly produce a << in your output, but an output that contains an unescaped << can never be well-formed XML. If your testing tool tries to parse such an output as if it were XML then that parsing process must fail with the error you are seeing.

Your later example of <body>&lt;&lt;</body> is a correct way to produce an escaped << in your output, and if your testing tool cannot handle that then the bug is in the tool rather than the XSLT code.