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 > 10">
. This works. I modified the code to use "<"
and that works fine too.
I tested <xsl:if test="price > 10">
(note the use of >
instead of the >
). 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)
views:
78answers:
3If 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.
The unencoded "opening" bracket <
is generally invalid in XML attribute values as per the XML spec.
While the "closing" bracket >
is allowed, using it is actually bad style (IMHO). XML attribute values have to be XML-encoded, period.
You can also see the answer to this on w3schools:
http://www.w3schools.com/xmL/xml_syntax.asp
Entity References
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.