Pacerier
Pacerier

Reputation: 89583

What's the big deal with using the `<` instead of simply `<` to do comparisons in XSLT?

Ok in XSLT i often see:

<xsl:if test="a &gt; b">

so what's the big deal with it?

I mean i changed it to <xsl:if test="a > b"> and its working fine.. why not just use this?

Upvotes: 4

Views: 5215

Answers (4)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

I mean i changed it to <xsl:if test="a < b"> and its working fine.. why not just use this?

If this is really true, your so called "XSLT processor" wasn't one. Any XSLT stylesheet must be a well-formed XML document. Any well-formed XML document cannot contain the character "<" inside an attribute value.

Therefore, please, correct the untrue statement in your question.

Upvotes: 0

Lumi
Lumi

Reputation: 15264

Nothing to do with XSLT, apart the fact that it's XML, and XML disallows < (but not >) in attribute values:

$ cat > a.xml
<elm a=">"/>
$ xmllint a.xml
<?xml version="1.0"?>
<elm a="&gt;"/>
$ cat > b.xml
<elm b="<"/>
$ xmllint b.xml
b.xml:1: parser error : Unescaped '<' not allowed in attributes values
<elm b="<"/>
        ^
b.xml:1: parser error : attributes construct error
<elm b="<"/>
        ^
b.xml:1: parser error : Couldn't find end of Start Tag elm line 1
<elm b="<"/>
        ^
b.xml:1: parser error : Extra content at the end of the document
<elm b="<"/>
        ^

Upvotes: 3

Chris Shaffer
Chris Shaffer

Reputation: 32565

XSLT files are XML files also; The XML Spec says not to use '<' and '&' literally except in certain contexts. So this is a matter of keeping well formed XML within your XSLT file.

Upvotes: 4

MikeyKennethR
MikeyKennethR

Reputation: 608

Because the <> are tag delimiters - therefore we need to escape this as an entity & l t ; or & # x 3 e ; as a sequence

Upvotes: 0

Related Questions