在 REST 数据代理的 XSL 转换中出现以下错误:
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
这是 XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="PCIresponse">
<dataset>
<xsl:for-each select="account-set/account">
<row>
<xsl:element name="field">
<xsl:attribute name="name">name</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="Account_Name" /></xsl:attribute>
</xsl:element>
</row>
</xsl:for-each>
</dataset>
</xsl:template>
最佳答案
事实证明,Java XSL 处理程序不喜欢在生成的转换的第一个节点之前有任何空格。
要解决此问题,您首先使用其自己的顶级模板设置根节点(即节点),然后从那里使用 apply-templates。工作版本如下所示:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="account-set">
<xsl:for-each select="account">
<row>
<xsl:element name="field">
<xsl:attribute name="name">name</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="Account_Name" /></xsl:attribute>
</xsl:element>
</row>
</xsl:for-each>
</xsl:template>
<xsl:template match="PCIresponse">
<dataset>
<xsl:apply-templates/>
</dataset>
</xsl:template>
</xsl:stylesheet>
此解决方案的最佳摘要位于:http://servicemix.apache.org/servicemix-saxon-orgw3cdomdomexception-hierarchyrequesterr.html
关于xslt - Aviarc REST Databroker 的 XSL 转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12257536/