2017-07-25 11 views
1

オーダーアイテムのリストを作成したいと思います。各アイテムについて、「アイテムID」フィールドと「住所ライン」フィールドを表示したい。前のフィールドのデータはアイテムの子要素に由来しますが、後者のデータはアイテム内で参照される一意のIDを使用してアイテムの親の兄弟からフェッチする必要があります。JasperReportsレポートアイテムリスト(xmlデータソース)の親の兄弟要素からIDでデータをフェッチする方法

問題を説明するために、簡略化されたxmlデータソースとレポートを作成しました。

<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> 

簡単な(間違った)報告書は次のとおりです:次のようにXMLデータが定義されている上記提供されたXMLデータの

<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> 

、私は報告書で、次の2つの行を見てみたいです:

  1. アイテムID:10001住所ライン:ストリート1、12345ベルリンドイツ
  2. アイテムID:10002住所ライン:ストリート3、12345ベルリンドイツ

この目標を達成するフィールドの説明またはxpathクエリが見つからないようです。誰も私の望む結果を得る方法を知っていますか?

答えて

1

XPath実行プログラムとしてXalanでJasperReportsを使用している場合(デフォルト設定の場合はnet.sf.jasperreports.xpath.executer.factoryを参照)、XSLT current関数を使用して現在のノードを参照できます。

あなたのケースでは、フィールドは次のようになります。

<field name="addressLine" class="java.lang.String"> 
    <fieldDescription><![CDATA[../../address[id = current()/installationAddressId]/addressLine]]></fieldDescription> 
</field> 
+0

はダダ、ありがとうございます!あなたの説明はまさに私が探していたものです! – Andy

関連する問題