将XML文档(片段)作为参数传递给chrome中的XSLT

passing an XML document (fragment) as parameter to XSLT in chrome

本文关键字:参数传递 chrome 中的 XSLT 文档 XML 片段      更新时间:2023-09-26

我想预加载一个XML文档(称为XMLParam),并使用setParameter将其作为参数传递给另一个文档( XML)的XSLT处理。

但是,XSLT不把它作为节点、节点列表或其他任何东西来处理,只是报告[object Element]

oXML = XMLDoc_load(sXMLURL);
oXMLParam = XMLDoc_load(sXMLParamURL);
oXSLT = XMLDoc_load(sXSLTURL);
var oXSLTProcessor = new XSLTProcessor();
oXSLTProcessor.importStylesheet(oXSLT);
oXSLTProcessor.setParameter(null,"oDocument",oXMLParam.documentElement);
var oResultDoc = oXSLTProcessor.transformToFragment(oXML, document); 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="oDocument"/>
    <xsl:template match="/"><p>Parameter:<xsl:copy-of select="$oDocument"/></p></xsl:template>

考虑传入要加载的文档的URL作为参数值,然后使用XSLT document函数用XSLT加载文档。这样你就有可能达到你想要的目的。

恐怕http://www.w3.org/TR/xslt#top-level-variables并没有详细说明处理器需要支持哪种类型才能从应用程序传递到样式表。听起来好像Chrome只是在你传入的DOM元素节点上调用toString,然后XSLT使用字符串而不是使用你想要的节点集。