我需要在以下XSL-FO模板中仅选择<fo:table ...>
节点的第一个匹配项,但xPath将返回所有这些节点。这是我在创建包含所有命名空间的包装元素后使用的XPath语句:
<fo:wrapper xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:j4luserext="xalan://com.java4less.xreport.fop.XLSTDummyExtension"
xmlns:j4lext="xalan://com.java4less.xreport.fop.XLSTExtension"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:j4lif="http://java4less.com/fop/iform">
{xsl:stylesheet/xsl:template/fo:root/fo:page-sequence/fo:flow/fo:table/
fo:table-body/fo:table-row/fo:table-cell/fo:block/fo:table[1]}
</fo:wrapper>
这是XSL-FO输入:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:j4lif="http://java4less.com/fop/iform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:j4lext="xalan://com.java4less.xreport.fop.XLSTExtension"
extension-element-prefixes="j4lext j4luserext"
xmlns:j4luserext="xalan://com.java4less.xreport.fop.XLSTDummyExtension">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="master0"
page-width="21.0cm" page-height="29.7cm" margin-top="2.0cm"
margin-bottom="2.0cm" margin-left="2.0cm" margin-right="2.0cm">
<fo:region-body region-name="body0" margin-top="1.5cm"
margin-bottom="1.5cm" />
<fo:region-before region-name="header0" extent="1.5cm" />
<fo:region-after region-name="footer0" extent="1.5cm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="master0">
<fo:static-content flow-name="header0">
<!-- 846098b14a344ae29ebeb7d3c3ae73c0 -->
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:static-content flow-name="footer0">
<!-- b468381816be4ef8bb31f448a8bf5b09 -->
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
<fo:flow flow-name="body0">
<!-- START Area Header -->
<!-- 4ce697eac861472391f5eac35a51db48 -->
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="1">
<fo:block>
<!-- START Area Detail -->
<!-- 7f22844da7e94220b5877bf7593e1dcb -->
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<!-- 63bbf10b61f44321913cffd695225a53 -->
<fo:table-header>
<fo:table-row background-color="#ffffff"
height="2.0cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff"
height="2.0cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row background-color="#ffffff"
height="4.0cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff"
height="4.0cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<!-- END Area Detail -->
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell number-columns-spanned="1">
<fo:block>
<!-- START Area Footer -->
<!-- ae182bb24f5648da9653ed5b997121c4 -->
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff"
height="1.5cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff"
height="1.5cm">
<fo:table-cell number-columns-spanned="1">
<fo:block></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<!-- END Area Footer -->
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<!-- END Area Header -->
<fo:block id="last-page" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
这是我期望的输出:
<fo:wrapper xmlns:j4lif="http://java4less.com/fop/iform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:j4lext="xalan://com.java4less.xreport.fop.XLSTExtension"
xmlns:j4luserext="xalan://com.java4less.xreport.fop.XLSTDummyExtension"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<!-- 63bbf10b61f44321913cffd695225a53 -->
<fo:table-header>
<fo:table-row background-color="#ffffff" height="2.0cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="2.0cm">
<fo:table-cell number-columns-spanned="1">
<fo:block />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
</fo:table>
</fo:wrapper>
这就是BaseX和Camel xQuery组件实际输出的内容:
<fo:wrapper xmlns:j4lif="http://java4less.com/fop/iform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:j4lext="xalan://com.java4less.xreport.fop.XLSTExtension"
xmlns:j4luserext="xalan://com.java4less.xreport.fop.XLSTDummyExtension"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<!-- 63bbf10b61f44321913cffd695225a53 -->
<fo:table-header>
<fo:table-row background-color="#ffffff" height="2.0cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="2.0cm">
<fo:table-cell number-columns-spanned="1">
<fo:block />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<fo:table-row background-color="#ffffff" height="4.0cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="4.0cm">
<fo:table-cell number-columns-spanned="1">
<fo:block />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:table width="17.0cm">
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell>
<fo:table>
<fo:table-column column-width="17.0cm" />
<fo:table-body>
<fo:table-row background-color="#ffffff" height="1.5cm">
<fo:table-cell number-columns-spanned="1">
<fo:block />
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:wrapper>
我不想要第二个表节点。由于/fo:table[1]
不起作用,我尝试在/fo:table[fo:table-column/fo:table-row[2]]
中放置谓词,并且不返回任何内容。奇怪的是,即使/fo:table[fo:table-column/fo:table-row]
也没有返回任何内容,但/fo:table[fo:table-column]
会返回相同的不需要的第二个表节点。任何人都知道这里发生了什么?
答案 0 :(得分:2)
您告诉XQuery实现返回每个fo:table
元素的第一个fo:block
元素,而不是整个文档的第一个匹配的fo:table
元素。将括号放在整个路径表达式周围,并在括号表达式上应用谓词:
(xsl:stylesheet/xsl:template/fo:root/fo:page-sequence/fo:flow/fo:table/
fo:table-body/fo:table-row/fo:table-cell/fo:block/fo:table)[1]