tags:

views:

67

answers:

1

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 < ?

+7  A: 

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.

Jon Skeet
[The right angle bracket (>) may be represented using the string >, and must, for compatibility, be escaped using either > or a character reference] does this mean that even though I can use it directly I shouldn't? cheers. T
runrunraygun
Yes, that's what it means.
John Gietzen
@runrunraygun: No. In fact I always use and recommend using `>`. This makes your code much more natural and understandable than when using `>`
Dimitre Novatchev
Cheers Dimitre, I'm think about instructing all our codes to use > in place of gt; and instead of using lt; invert the statement and use > unless other considerations make that a less natural option.
runrunraygun