What's the big deal with using the `<` inst

2019-05-07 20:44发布

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?

标签: xml xslt
4条回答
欢心
2楼-- · 2019-05-07 21:19

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.

查看更多
ら.Afraid
3楼-- · 2019-05-07 21:22

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="<"/>
        ^
查看更多
小情绪 Triste *
4楼-- · 2019-05-07 21:24

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

查看更多
SAY GOODBYE
5楼-- · 2019-05-07 21:31

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.

查看更多
登录 后发表回答