xml – 为什么在xsl:variable中存储属性导致错误XTDE0420?
此XSLT构造属性并将结果存储在变量中.然后将变量复制为元素< test>的唯一子元素:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all"> <xsl:template match="/"> <xsl:variable name="some-attribute"> <xsl:attribute name="test">value</xsl:attribute> </xsl:variable> <test> <xsl:copy-of select="$some-attribute" /> </test> </xsl:template> </xsl:stylesheet> 虽然这似乎只是简单地插入属性作为元素的子元素,但结果是抛出错误:XTDE0420:无法创建父文件节点的父节点. 解决方法
关键信息在
section 9.3 of the XSLT 2.0 spec,“Values of Variables and Parameters”中解释:
实质上,没有select属性且没有as属性的变量的值是文档节点. 不可能在示例中修改变量以使用select,但可以将其更改为用作: <xsl:variable name="some-attribute" as="item()*"> <xsl:attribute name="test">value</xsl:attribute> </xsl:variable> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |