Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Less-than operator causes error "not well-formed" in xsl-if

Tags:

xml

xslt

I'm going through the w3cschools XSLT tutorial, and I am at this page: xsl-if.

On that page (in red) is the text <xsl:if test="price &gt; 10">. This works. I modified the code to use "&lt;" and that works fine too.

I tested <xsl:if test="price > 10"> (note the use of > instead of the &gt;). This works too.

But this fails: <xsl:if test="price < 10">. Error is XML Parsing Error: not well-formed and it points to the < symbol in the expression.

If the > symbol worked fine, why did using the < fail? (I'm using FireFox)

like image 770
Zabba Avatar asked Aug 19 '10 21:08

Zabba


1 Answers

If the > symbol worked fine, why did using the < fail? (I'm using FireFox)

Because the "<" character is one of the few that are illegal within an attribute value (it is the start-of tag character).

From the XML Specification

[10]    AttValue    ::=    '"' ([^<&"] | Reference)* '"' 

As can be clearly seen, the "<" and "&" characters are not allowed in any attribute value.

Update: As noticed by @Tomalak, the above should read:

As can be clearly seen, the "<" and "&" characters (unless the latter is part of an entity reference or character reference) are not allowed in any attribute value.

like image 164
Dimitre Novatchev Avatar answered Oct 20 '22 00:10

Dimitre Novatchev