xslt for-each 中,使用动态select

       朋友发来一简单的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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值