Jump to content
We've recently updated our Privacy Statement, available here ×

How to dereference an XML node within a report row


rgarrison

Recommended Posts

i have an xml data source with the following structure

 

 

<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

  <folder name="Application" id="8194d772" type="application">

    <element type="ApplicationComponent" id="71031456" name="Apache Sling"/>

    <element type="ApplicationComponent" id="f0baee63" name="Apache"/>

  </folder>

  <folder name="Relations" id="df19ab5b" type="relations">

    <element type="AggregationRelationship" id="b2adb66d" source="f0baee63" target="71031456"/>

    <element type="CompositionRelationship" id="ca16a011" source="f0baee63" target="71031456"/>

  </folder>

</model>

 

the report should list the rows like this...

 

|  source  | relation                | target       |

|  Apache  | AggregationRelationship | Apache Sling | 

 

The datasource is setup as an XML data source with the xpath "/model/folder[@type=relations]/element"

 

That setup exposes the relations fields, but how to de-reference the source and target guids within the same report or subreport so that it prints into a single row doesn't appear so obvious.

 

the xpath to dereference source/target would look like 

"/model/folder[@type=application]/element[id=$F(source)]/name"

 

(after 12 hours of head banging to get here...)

i could use some help figuring out to apply that knowledge to a report design...   

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

If you use Xalan as XPath engine (see the net.sf.jasperreports.xpath.executer.factory property), you can take advantage of the current() function and map a report field to something like /model/folder[@type=application]/element[@id=current()/@source]/@name

This will not work with Jaxen, which doesn't have the current() function (which is not actually part of XPath 1.0 but a XSLT extension).

An alternative solution is to use a list element with a subdataset that selects the value given $F{source}.  The exact way of doing that depends on the way in which the report data source is defined (that is on whether the report directly receives an XML data source or it has the XPath expression as report query).

Regards,

Lucian

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...