xslt for-each 中,使用动态select
2013-01-01 22:11
387 查看
朋友发来一简单的xml和xsl,如下
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="./xsl/test.xsl" ?>
<root point_id="1" point_name="海康嵌入式DVR51图像" week="6"
year="2012" month="12" day="23" >
<w_0 >
<r_0 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_0>
<r_1 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_1>
<r_2 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_2>
<r_3 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_3></w_0>
<w_1 >
<r_0 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_0>
<r_1 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_1>
<r_2 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_2>
<r_3 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_3></w_1>
</root>
XSLT 内容:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<xsl:variable name="week" select='concat("w_",@week)'/>
<xsl:for-each
select="$week/*">
<!--do something here-->
</xsl:for-each>
希望xsl能够根据xml中week属性值动态获取子节点中对应的数据节点
运行时抛出
Expression does not return a DOM node. -->$week<-- 的错误
经过搜索,找到一下的解决方法,用下面代码替换即可上述红色代码
select="*[local-name() = $week]/*" 或者 select="*[contains(local-name(), $week)]/*“
full dynamic XPath evaluation isn't part of either XSLT 1.0/XPath 1.0 or XSLT 2.0/XPath 2.0
http://stackoverflow.com/questions/7443426/dynamic-xslt-for-each-iteration
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="./xsl/test.xsl" ?>
<root point_id="1" point_name="海康嵌入式DVR51图像" week="6"
year="2012" month="12" day="23" >
<w_0 >
<r_0 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_0>
<r_1 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_1>
<r_2 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_2>
<r_3 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_3></w_0>
<w_1 >
<r_0 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_0>
<r_1 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_1>
<r_2 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_2>
<r_3 start_hour="0" start_minute="0" stop_hour="0" stop_minute="0" ></r_3></w_1>
</root>
XSLT 内容:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<xsl:variable name="week" select='concat("w_",@week)'/>
<xsl:for-each
select="$week/*">
<!--do something here-->
</xsl:for-each>
希望xsl能够根据xml中week属性值动态获取子节点中对应的数据节点
运行时抛出
Expression does not return a DOM node. -->$week<-- 的错误
经过搜索,找到一下的解决方法,用下面代码替换即可上述红色代码
select="*[local-name() = $week]/*" 或者 select="*[contains(local-name(), $week)]/*“
full dynamic XPath evaluation isn't part of either XSLT 1.0/XPath 1.0 or XSLT 2.0/XPath 2.0
http://stackoverflow.com/questions/7443426/dynamic-xslt-for-each-iteration
相关文章推荐
- 在XSLT中对for-each语句使用distinct操作
- 在XSLT中对for-each语句使用distinct操作
- select 下拉菜单Option对象使用add(elements,index)方法动态添加
- sp_MSforeachtable使用方法
- 使用SP_MSForEachTable重建一个数据库中所有的索引
- sp_MSforeachtable使用方法
- 系统存储过程sp_MSforeachtable的使用说明
- jquery.cxselect.js的使用案例 (动态数据的三级联动)
- for_each()算法的使用
- 使用ajax动态加载select下拉框
- for_each的各种情况下的使用详解
- MySQL 使用SELECT ... FOR UPDATE 做事务写入前的确认(转)
- mybatis使用动态sql时报错:There is no getter for property named '*' in 'class java.lang.String
- C++中std::for_each的使用
- for_each使用方法详解
- 如何正確的使用迴圈(使用for_each)? (C/C++) (STL) (template)
- 使用xslt动态生成javabean的代码
- java 中能否使用 动态加载的类(Class.forName) 来做类型转换?
- Select中使用js动态修改了Option时如何触发onchange事件
- 使用js对select动态添加和删除OPTION示例代码