无法在xsl脚本中传递XML

Nitish singla

以下是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>

请帮忙。

马丁·霍恩(Martin Honnen)

我不明白为什么您坚持使用诸如扩展脚本之类的专有功能来简单地选择节点并输出其值,这就是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.xmlIE的输出

Book Details


XPath
4

Script
4

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法通过表中的XSL显示XML信息

无法通过XSL访问XML中的元素值

从外部XML进行XSL查找无法在vbscript中工作

将参数从脚本传递到XSL

无法将Powershell中的变量从函数传递到脚本

XSL:从VBS脚本获取XML对象

改进的XSL脚本,带有XML文件中的链接和应用模板

如何通过soap xml中的rgb值将其转换为xsl并传递rgb值

在/在XML / XSL中可见

无法将命令行参数传递给bash脚本中嵌入的awk脚本

无法在Postman预请求脚本中访问XML响应

无法在 bash 脚本中关联或分组每组 xml 属性

无法使用脚本在HTML中显示我的XML?

XML-XSL无法正常工作

我无法从xml的xsl编码中获得子循环中的根节点数据

xsl:template中的<head>元素被忽略,XML,XSL,XHTML

在脚本中传递php变量

在 BigQuery 脚本中传递参数

使用PowerShell无法将脚本块中的变量传递给我的其余代码

chrome扩展程序中的内容脚本和背景页面之间的消息传递无法正常工作

我无法将变量从函数传递给Shell脚本中的主代码

无法将Shell脚本中以空格分隔的参数传递给C ++可执行文件

无法将形式中的一个变量传递/处理到搜索脚本

无法将格式化的Get-ADOrganizationlUnit输出传递给脚本中的函数

无法将批处理脚本的参数正确传递到循环语句中的命令中

无法将参数传递给jar启动器到shell脚本中

无法在脚本中将密码传递给su

编写嵌套的shell脚本-无法传递参数

在 xsl 中求和 xml 逗号值