使用XQUERY(baseX),我希望在某些Jasper报告中提供信息。我需要在ELEMENT cdata中返回文本

问题描述 投票:1回答:1

使用记事本++,我具有包含如下所示的cdata的元素的路径:

/jasperReport[1]/columnHeader[1]/band[1]/staticText[1]/text[1]

源看起来与此类似:

<jasperReport>
    <columnHeader>
        <band height="22" >
            <staticText>
                <reportElement x="0" y="0" width="48" height="20" uuid="one"/>
                <box leftPadding="1">
                    <pen lineWidth="0.5"/>
                    <topPen lineWidth="0.5"/>
                    <leftPen lineWidth="0.5"/>
                    <bottomPen lineWidth="0.5"/>
                    <rightPen lineWidth="0.5"/>
                </box>
                <textElement>
                    <font size="8" />
                </textElement>
                <text><![CDATA[MYNUM]]></text>
            </staticText>

我正在尝试使用XQUERY返回与XML片段倒数第二行相似的值“ MYNUM”。在这种情况下,它将告诉我标题的特定部分中包含文本“ MYNUM”。我打算在Mac上使用XQUERY和BaseX返回更多类似报告的更完整信息。

因此,我可以在一组报告文件上运行xquery,这些报告文件将输出类似以下内容:

/ filenameofreport.data

<Header>
<reportElement>x=0 y=0 value=MYNUM</reportElement>
<reportElement>x=10 y=0 value=THATNUM</reportElement>
</HEADER>

确定,我知道此输入查询:

declare namespace abc="http://jasperreports.sourceforge.net/jasperreports";

for $document in collection("temp")
where document-uri($document) = "/temp/Daily_P1NoAssign_.data"
return
 for $thefield in  $document//abc:jasperReport[1]/abc:columnHeader[1]/abc:band[1]/abc:staticText[1]/abc:textElement[1]/abc:font
   let $fontsize := string-join(("<font>",$thefield/@size,"</font>"))
   let $docgroup := xs:string((document-uri($document)))
   group by $docgroup
   order by $docgroup
   return ( element {"jasperReport"} { $docgroup }  , $fontsize)

产生此输出:

<jasperReport>/temp/Daily_P1NoAssign_.data</jasperReport>
<font>8</font>

所以...此输入针对textElement的同级对象应该具有正确的元素,但我不知道如何输出数据

xquery:

declare namespace abc="http://jasperreports.sourceforge.net/jasperreports";

for $document in collection("temp")
where document-uri($document) = "/temp/Daily_P1NoAssign_.data"
return
 for $thefield in  $document//abc:jasperReport[1]/abc:columnHeader[1]/abc:band[1]/abc:staticText[1]/abc:text[1]
   let $textinfo := string-join(("<text>",$thefield/*,"</text>"))
   let $docgroup := xs:string((document-uri($document)))
   group by $docgroup
   order by $docgroup
   return ( element {"jasperReport"} { $docgroup }  , $textinfo)

返回:

<jasperReport>/temp/Daily_P1NoAssign_.data</jasperReport>
<text></text>

更新:哦,我想起来了,几乎一切都想通了-到目前为止,这里是第一个解决方案,但是我想输出的数据略有不同...

declare namespace abc="http://jasperreports.sourceforge.net/jasperreports";

for $document in collection("temp")
where document-uri($document) = "/temp/Daily_P1NoAssign_.data"
return
 for $thefield in  $document//abc:jasperReport[1]/abc:columnHeader[1]/abc:band[1]/abc:staticText/abc:text[1]
   let $textinfo3 := $thefield/text()
   let $docgroup := xs:string((document-uri($document)))
   group by $docgroup
   order by $docgroup
   return ( element {"jasperReport"} { $docgroup }  ,$textinfo3)

用WONUM WORKTPE等在单独的行上返回此:

<jasperReport>/temp/Daily_P1NoAssign_.data</jasperReport>
WONUM
WORKTYPE
LOCATION
MODELNUM
SERIALNUM
REPORTDATE
STATUSDATE
STATUS
OWNER
OWNERGROUP
WARRANTYEXPDATE
INWARRANTY

有没有一种方法可以将WONUM WORKTYPE等全部返回一行?

<jasperReport>/temp/Daily_P1NoAssign_.data</jasperReport>
WONUM WORKTYPE LOCATION MODELNUM SERIALNUM REPORTDATE STATUSDATE STATUS OWNER OWNERGROUP WARRANTYEXPDATE INWARRANTY
xquery cdata
1个回答
0
投票

消除换行字符的最简单方法是使用normalize-space()方法。

两个

let $textinfo3 := normalize-space($thefield/text())

let $textinfo3 := normalize-space(string-join($thefield/text(), " "))
© www.soinside.com 2019 - 2024. All rights reserved.