[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.birt] Re: Report parameters in XPath expressions

Sebastian,

Add a beforeOpen script to the datasource with a value something like:
this.queryText = "table1#-TNAME-#table1#:#[/companies/company[@id='" + params["companyid"].value +"']/employee]#:#{id;STRING;/@id},{companyid;STRING;../@id}"


See attached example.  Modify the xml source to point at your xml.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design"; version="3.2.17" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.3.1.v20080911 Build &lt;2.3.1.v20080922-1151></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<parameters>
<scalar-parameter name="companyid" id="11">
<property name="valueType">static</property>
<property name="dataType">string</property>
<property name="paramType">simple</property>
<property name="controlType">list-box</property>
<property name="mustMatch">true</property>
<property name="fixedOrder">true</property>
<property name="defaultValue">c2</property>
<property name="distinct">true</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
<list-property name="selectionList">
<structure>
<property name="value">c1</property>
<property name="label">company1</property>
</structure>
<structure>
<property name="value">c2</property>
<property name="label">company2</property>
</structure>
</list-property>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="Data Source" id="6">
<property name="FILELIST">C:\xfer\company.xml</property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set extensionID="org.eclipse.datatools.enablement.oda.xml.dataSet" name="Data Set1" id="10">
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">id</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">companyid</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="beforeOpen"><![CDATA[this.queryText = "table1#-TNAME-#table1#:#[/companies/company[@id='" + params["companyid"].value +"']/employee]#:#{id;STRING;/@id},{companyid;STRING;../@id}"]]></method>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">id</property>
<property name="nativeName">id</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">companyid</property>
<property name="nativeName">companyid</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
</list-property>
<property name="queryText">table0#-TNAME-#table0#:#[/companies/company/employee]#:#{id;STRING;/@id},{companyid;STRING;../@id}</property>
<xml-property name="designerValues"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<model:DesignValues xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"; xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel";>
<Version>1.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>id</design:name>
<design:position>1</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>-1</design:precision>
<design:scale>-1</design:scale>
<design:nullability>Unknown</design:nullability>
</design:attributes>
<design:usageHints>
<design:label>id</design:label>
<design:formattingHints/>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>]]></xml-property>
<list-property name="privateDriverProperties">
<ex-property>
<name>MAX_ROW</name>
<value>-1</value>
</ex-property>
<ex-property>
<name>XML_FILE</name>
</ex-property>
</list-property>
</oda-data-set>
</data-sets>
<styles>
<style name="crosstab" id="4">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="12">
<property name="width">100%</property>
<property name="dataSet">Data Set1</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">id</property>
<property name="displayName">id</property>
<expression name="expression">dataSetRow["id"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">companyid</property>
<property name="displayName">companyid</property>
<expression name="expression">dataSetRow["companyid"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="26"/>
<column id="27"/>
<header>
<row id="13">
<cell id="14">
<label id="15">
<text-property name="text">id</text-property>
</label>
</cell>
<cell id="16">
<label id="17">
<text-property name="text">companyid</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="18">
<cell id="19">
<data id="20">
<property name="resultSetColumn">id</property>
</data>
</cell>
<cell id="21">
<data id="22">
<property name="resultSetColumn">companyid</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="23">
<cell id="24"/>
<cell id="25"/>
</row>
</footer>
</table>
</body>
</report>



Sebastian Pogorzelski wrote:
Hello,

I have the following example XML doc as a data source:

<companies>
    <company id="c1">
        <employee id="e1"/>
        <employee id="e2"/>
    </company>
    <company id="c2">
        <employee id="e1"/>
        <employee id="e2"/>
        <employee id="e3"/>
    </company>
</companies>

I have created a dynamic combo box report parameter called 'cid' of type string, populated from a simple /companies/company/@id dataset.
I am trying to create an 'employees' dataset with the following row mapping:


/companies/company[@id={?cid?}]/employee

the result is empty.

Other times i get unpredictable behavior, e.g. error:
A BIRT exception occurred.
Plug-in Provider:Eclipse.org
Plug-in Name:BIRT Data Engine
Plug-in ID:org.eclipse.birt.data
Version:2.3.1.v20080829
Error Code:odaconsumer.CannotPrepareStatement
Error Message:Failed to prepare the following query for the data set type org.eclipse.datatools.enablement.oda.xml.dataSet.
The filter definition is invalid.


Sometimes the error doesn't show up, but the row mapping field contents dissappear.


how do i insert a report parameter into an XPath expression in row mapping when creating a dataset from XML file?


Do i have to escape inverted commas?

Thanks
Sp