简体   繁体   English

<xsl:when test="string-length( xpath value) is not working after xslt version upgrade to xslt 3.0 version

[英]<xsl:when test="string-length( xpath value) is not working after xslt version upgrade to xslt 3.0 version

<xsl:when test="string-length( xpath value) is not working after xslt version upgrade to xslt 3.0 version> <xsl:when test="string-length(xpath value) 在 xslt 版本升级到 xslt 3.0 版本后不起作用>

it is giving error它给出了错误

XPTY0004 A sequence of more than one item is not allowed as the first argument of fn:string-length() ("", " ") XPTY0004 多个项目的序列不允许作为 fn:string-length() ("", " ") 的第一个参数

but it was working correctly with 1.1 version但它在 1.1 版本中正常工作

If you run XSLT version="1.0" code (and probably version="1.1" code as well) through an XSLT 2 or 3 processor that supports backwards compatible XPath 1.0 mode then some XPath 1.0 specific rules are applied, mainly that functions receiving sequences/node-sets but expecting a single item use the first item in the node-set/sequence.如果您通过支持向后兼容 XPath 1.0 模式的 XSLT 2 或 3 处理器运行 XSLT version="1.0"代码(可能还有version="1.1"代码),那么将应用一些 XPath 1.0 特定规则,主要是接收序列的函数/node-sets 但期望单个项目使用节点集/序列中的第一项。

In standards mode (XSLT version="2.0" or version="3.0") this is not the case, so you need to make sure that your argument to string-length is a single string and not a sequence of strings.在标准模式(XSLT version="2.0" 或 version="3.0")中,情况并非如此,因此您需要确保string-length的参数是单个字符串而不是字符串序列。

In XSLT 1.0, if you called a function such as string-length() supplying a set of multiple nodes in the argument, it ignored all nodes except the first.在 XSLT 1.0 中,如果调用诸如string-length()之类的函数并在参数中提供一组多个节点,它会忽略除第一个节点之外的所有节点。

This led to so many bugs that the rule was changed in 2.0, so supplying more than one node is an error.这导致了太多错误,以至于规则在 2.0 中被更改,因此提供多个节点是错误的。 If you want the first node rule, change string-length(PATH) to string-length((PATH)[1]) .如果您想要第一个节点规则,请将string-length(PATH)更改为string-length((PATH)[1]) (You can also leave the stylesheet version set to 1.0 to get backwards compatibility mode.) (您也可以将样式表版本设置为 1.0 以获得向后兼容模式。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM