【发布时间】:2014-08-05 19:10:40
【问题描述】:
我试图弄清楚如何将 XML 传递到 XSLT 文档中并像在任何节点上一样对其进行解析。
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:param name="xmlparam"></xsl:param>
<xsl:template match="/">
<xsl:value-of select="node()"></xsl:value-of>
<xsl:value-of select="$xmlparam/coll"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
xml参数:
<?xml version="1.0" encoding="UTF-8"?>
<coll>
<title>Test</title>
<text>Some text</text>
</coll>
输入:
<?xml version="1.0" encoding="UTF-8"?>
<coll>
Root doc
</coll>
输出:
<?xml version="1.0" encoding="UTF-8"?>
Root doc
XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:untypedAtomic
有谁知道如何解析作为参数传入 XSLT 的 XML?由于某些限制,我无法读取文件,它需要是一个参数。
【问题讨论】:
-
您使用哪个 XSLT 2.0 处理器,如何/在哪里传递参数?这一切都取决于您使用的 XSLT 处理器以及它提供的用于解析 XML 和传递参数的 API,例如,请参阅 stackoverflow.com/questions/24077219/… 以获取具有 .NET 版本的 Saxon 9 的示例。
标签: xslt