开发者

What's the big deal with using the `&lt;` 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.. 开发者_如何学Cwhy not just use this?


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.


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="<"/>
        ^


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜