gpt4 book ai didi

xml - 如何在 jasper 中反转子报表的 xpath?

转载 作者:行者123 更新时间:2023-12-03 06:53:47 26 4
gpt4 key购买 nike

当我创建子报表时,我尝试以相反的方向浏览 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 的一般问题:

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

最佳答案

问题是您正在尝试 subDataSource

Creates a sub data source using the current node (record) as the root of the document

因此,您将在 child1 处创建一个具有新根的新文档(XPath 无法超越此新根)

而是使用 dataSource

Creates a sub data source using as root document the document used by "this" data source.

在您的示例中,这将是:

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

关于xml - 如何在 jasper 中反转子报表的 xpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52698787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com