Javascript 无法在xsl脚本中传递XML

Javascript 无法在xsl脚本中传递XML,javascript,xml,xslt,client-side,Javascript,Xml,Xslt,Client Side,下面是XML和XSL,我想将完整的XML节点传递给XSL脚本,以便在该节点上执行一些操作,我不想使用XPATH,而是想在msxslscript中使用selectsinglenode进行操作 XML 革命 1. 馅饼的生命 5. XSL 函数getNode(节点){ 返回节点。选择单节点(“书籍/书籍/数量/@value”); } 书籍详情 请提供帮助。我不明白为什么您坚持使用专有功能(如扩展脚本)来简单地选择节点并输出它们的值,因为XSLT和XPath就是用于此目的的,但如果您需要一个示

下面是XML和XSL,我想将完整的XML节点传递给XSL脚本,以便在该节点上执行一些操作,我不想使用XPATH,而是想在msxslscript中使用selectsinglenode进行操作

XML


革命
1.
馅饼的生命
5.
XSL


函数getNode(节点){
返回节点。选择单节点(“书籍/书籍/数量/@value”);
}
书籍详情

请提供帮助。

我不明白为什么您坚持使用专有功能(如扩展脚本)来简单地选择节点并输出它们的值,因为XSLT和XPath就是用于此目的的,但如果您需要一个示例,那么使用IE,以下功能对我有效:

<?xml-stylesheet type="text/xsl" href="test2014110601.xsl"?>
<books>
<book>
<name>Revolution</name>
<qty value="4">1</qty>
</book>
<book>
<name>Life of a pie</name>
<qty value="4">5</qty>
</book>
</books>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:user="http://example/com/user"
  exclude-result-prefixes="msxsl user">

<msxsl:script language="javascript" implements-prefix="user">
function getNode(nodeSelection) {
  return nodeSelection.item(0).selectSingleNode("book/qty/@value");
}
</msxsl:script>

<xsl:output method="html" indent="yes" version="4.01"/>

<xsl:template match="/">
  <xsl:variable name="rootElement" select="books"/>
  <html>
    <body>
      <h2>Book Details</h2>
      <div>
        <h3>XPath</h3>
        <xsl:value-of select="$rootElement/book/qty/@value"/>
      </div>
      <div>
        <h3>Script</h3>
        <xsl:value-of select="user:getNode($rootElement)"/>
      </div>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

我看不到您的示例中使用了
selectSingleNode
,因此如果您面临的问题是
selectSingleNode
,请展示一个示例,详细解释您期望的结果以及您得到的结果如何不同。或者至少为张贴的样本解释问题所在,即,您期望的结果以及您得到的结果如何不同。你有什么错误吗?你在用IE吗?否则,就根本不支持使用msxsl:script的整个方法。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:user="com.nitish">
<msxsl:script language="javascript" implements-prefix="user" >
function getNode(node){

return node.selectSingleNode("books/book/qty/@value");

}
</msxsl:script>

<xsl:template match="/">


<html>
<body>
<h2>Book Details</h2>
<table xmlns:h="http://www.w3.org/TR/html4/" border="1px" cellspacing="20px">
<xsl:variable name="rootNode" select="books"/>
<xsl:for-each select="//book">
<tr><td><xsl:value-of select="user:getNode($rootNode)"/>
</td></tr>
</xsl:for-each>
</table>
</body>
</html>

</xsl:template>

</xsl:stylesheet>
<?xml-stylesheet type="text/xsl" href="test2014110601.xsl"?>
<books>
<book>
<name>Revolution</name>
<qty value="4">1</qty>
</book>
<book>
<name>Life of a pie</name>
<qty value="4">5</qty>
</book>
</books>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:user="http://example/com/user"
  exclude-result-prefixes="msxsl user">

<msxsl:script language="javascript" implements-prefix="user">
function getNode(nodeSelection) {
  return nodeSelection.item(0).selectSingleNode("book/qty/@value");
}
</msxsl:script>

<xsl:output method="html" indent="yes" version="4.01"/>

<xsl:template match="/">
  <xsl:variable name="rootElement" select="books"/>
  <html>
    <body>
      <h2>Book Details</h2>
      <div>
        <h3>XPath</h3>
        <xsl:value-of select="$rootElement/book/qty/@value"/>
      </div>
      <div>
        <h3>Script</h3>
        <xsl:value-of select="user:getNode($rootElement)"/>
      </div>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>
Book Details


XPath
4

Script
4