【问题标题】:How to reverse xpath for subreport in jasper?如何在jasper中反转子报告的xpath?
【发布时间】:2018-10-08 09:03:16
【问题描述】:

我在创建子报表时尝试反向浏览 xml 节点,但这不起作用。我的报告 XPath 是 /root/parent/child1,我希望子报告将 /root/parent/child2 作为 XPath

<root>
  <parent>
    <child1>
    </child1>
    <child2>
    </child2>
  </parent>
</root>

我在数据源表达式中写了以下内容:

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//../child2")

我的问题是关于 xpath 的一般问题:

是否允许在数据源表达式中使用“..”或“../..”来引用祖先?

【问题讨论】:

    标签: xml xpath jasper-reports xmldatasource


    【解决方案1】:

    问题是你正在尝试subDataSource

    创建一个子数据源使用当前节点(记录)作为文档的根

    因此,您正在使用 child1 的新根创建一个新文档(XPath 不能超出这个新根)

    改为使用dataSource

    创建一个子数据源使用“this”数据源使用的文档作为根文档

    在你的例子中是:

    ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/root/parent/child2")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多