xpath - How to fetch data by id from parent's sibling element in JasperReports report items list (xml datasource) -


i want create list of order items; each item, want display "item id" , "address line" field; data of former field comes child element on item, data latter must fetched sibling of item's parent using unique id referenced in item.

i've created simplified xml data source , report in in order illustrate problem. xml data defined follows:

<data> <productorder>     <item>         <id>10001</id>         <installationaddressid>1</installationaddressid>     </item>     <item>         <id>10002</id>         <installationaddressid>3</installationaddressid>     </item> </productorder> <address>     <id>1</id>     <addressline>street 1, 12345 berlin germany</addressline> </address> <address>     <id>2</id>     <addressline>street 2, 12345 berlin germany</addressline> </address> <address>     <id>3</id>     <addressline>street 3, 12345 berlin germany</addressline> </address> </data> 

the simple (incorrect) report is:

<jasperreport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="simpleorderitemreport" pagewidth="595" pageheight="842" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20" uuid="0d316a3a-9d1c-4483-bf7d-d1bd9165e0cb"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="simpleorderitemreportdataadapter"/> <subdataset name="orderitemlist" uuid="c1a7dc7b-2bc3-4f1f-bab9-ae6e3b207739">     <property name="com.jaspersoft.studio.data.defaultdataadapter" value="simpleorderitemreportdataadapter"/>     <querystring language="xpath">         <![cdata[/data/productorder/item]]>     </querystring>     <field name="id_1" class="java.lang.string">         <fielddescription><![cdata[id]]></fielddescription>     </field>     <field name="installationaddressid_1" class="java.lang.string">         <fielddescription><![cdata[installationaddressid]]></fielddescription>     </field>     <field name="addressline" class="java.lang.string">         <fielddescription><![cdata[../../address/addressline]]></fielddescription>     </field> </subdataset> <querystring language="xpath">     <![cdata[/data]]> </querystring> <detail>     <band height="125" splittype="stretch">         <componentelement>             <reportelement x="124" y="19" width="390" height="30" uuid="84a1e8b2-13df-4391-9cdd-39a9d4d79434"/>             <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemalocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">                 <datasetrun subdataset="orderitemlist" uuid="0d232993-a132-45ff-813c-d00d8a685d9e">                     <datasourceexpression><![cdata[((net.sf.jasperreports.engine.data.jrxmldatasource)$p{report_data_source}).subdatasource("/data/productorder/item")]]></datasourceexpression>                 </datasetrun>                 <jr:listcontents height="30" width="390">                     <textfield>                         <reportelement x="40" y="0" width="40" height="30" uuid="2b9a8530-32e3-4ecb-8dc4-3d8d9d30b191"/>                         <textelement textalignment="left" verticalalignment="top"/>                         <textfieldexpression><![cdata[$f{id_1}]]></textfieldexpression>                     </textfield>                     <textfield>                         <reportelement x="190" y="0" width="200" height="30" uuid="d570993d-201b-4a43-9147-73036dd0cf11"/>                         <textelement textalignment="left" verticalalignment="top"/>                         <textfieldexpression><![cdata[$f{addressline}]]></textfieldexpression>                     </textfield>                     <statictext>                         <reportelement x="0" y="0" width="40" height="30" uuid="b96b0be3-fa58-42f1-8270-004a08a7c3df"/>                         <textelement verticalalignment="top"/>                         <text><![cdata[item id:]]></text>                     </statictext>                     <statictext>                         <reportelement x="90" y="0" width="100" height="30" uuid="f85e298c-e3e0-42e3-bd0d-fc7c7808c2f1"/>                         <textelement verticalalignment="top"/>                         <text><![cdata[address line:]]></text>                     </statictext>                 </jr:listcontents>             </jr:list>         </componentelement>     </band> </detail> </jasperreport> 

for xml data provided above, want see following 2 rows in report:

  1. item id: 10001 address line: street 1, 12345 berlin germany
  2. item id: 10002 address line: street 3, 12345 berlin germany

i can't seem find field description or xpath query achieve goal. know how desired result?

if use jasperreports xalan xpath executer (and that's default configuration, see net.sf.jasperreports.xpath.executer.factory), can use xslt current function refer current node.

in case, field should this:

<field name="addressline" class="java.lang.string">     <fielddescription><![cdata[../../address[id = current()/installationaddressid]/addressline]]></fielddescription> </field> 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -