Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In xpath why can I use greater-than symbol > but not less-than <

Using c#3 compiled transforms the following seems to work just fine...

<xsl:choose>
    <xsl:when test="$valA > $valB">
        <xsl:value-of select="$maxUnder" />
    </xsl:when>
    <xsl:when test="$valA &lt; $valC">
        <xsl:value-of select="$maxOver" />
    </xsl:when>
</xsl:choose>

However if i dare use a < in place of &lt; it gives an error...

<xsl:choose>
    <xsl:when test="$valA > $valB">
        <xsl:value-of select="$maxUnder" />
    </xsl:when>
    <xsl:when test="$valA < $valC">
        <xsl:value-of select="$maxOver" />
    </xsl:when>
</xsl:choose>

System.Xml.XmlException: '<', hexadecimal value 0x3C, is an invalid attribute character.

So why is > ok and not < ?

like image 670
gingerbreadboy Avatar asked Jun 13 '10 13:06

gingerbreadboy


People also ask

What is the meaning of '/' in XPath?

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

How do you use greater than and less than in XSLT?

You're always safe using &gt; here, although some XSLT processors process the greater-than sign correctly if you use > instead. If you need to use the less-than operator ( < ), you'll have to use the &lt; entity.

How do you write conditional XPath expression?

To define an XPath expression that checks if a string element is empty, you must use the operator != . This example shows how to define an XPath expression that evaluates to true when a repeating element, which is referred to as a sequence, is empty. The effective Boolean value of an empty sequence is false.


1 Answers

Because > isn't a reserved character in XML, but < is.

From section 2.4 of the XML 1.0 spec (5th edition):

The ampersand character (&) and the left angle bracket (<) must not appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings "&amp;" and "&lt;" respectively. The right angle bracket (>) may be represented using the string "&gt;", and must, for compatibility, be escaped using either "&gt;" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section.

like image 128
Jon Skeet Avatar answered Nov 07 '22 07:11

Jon Skeet