以下是XML和XSL,我想将完整的xml节点传递给xsl脚本以对该节点执行一些操作,并且我不想使用XPATH,也不想在msxslscript中使用selectsinglenode进行操作。
XML格式
<?xml version="1.0" ?>
<?xml-stylesheet href="doc.xsl" type="text/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>
XSL
<?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>
请帮忙。
我不明白为什么您坚持使用诸如扩展脚本之类的专有功能来简单地选择节点并输出其值,这就是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>
在线http://home.arcor.de/martin.honnen/xslt/test2014110601.xml。IE的输出
Book Details
XPath
4
Script
4
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句