Variables in XPath for XML Datasource

By: lOtR - lotr44
Variables in XPath for XML Datasource
2005-08-04 08:27
I am using a XML datasource, and would like to use a variable (or parameter, or somewhat dynamic) in the XPath "description" of a Field.

To be clearer, I would like my field to point to something like:
/myelement/details[@language='$P{language}']/myvalue

Does anyone have an idea on how i could do something like that ?

Thanks in advance.
2004 IR Help's picture
Joined: Aug 17 2006 - 3:49am
Last seen: 15 years 9 months ago

2 Answers:

I have the same problem...
astrid.grytberg@vsk.se's picture
Joined: May 2 2007 - 8:40pm
Last seen: 7 years 1 month ago
Hi,

This is not supported by our current XPath query executer and corresponding XML data source.

You could log this as a feature request here:
http://jasperforge.org/sf/tracker/do/listArtifacts/projects.jasperreport...
or you could go ahead and try to implement a new query executer that would be able to recognize parameter references inside field descriptions and make use of them, just like it currently does with parameter references inside the <queryString> tag.

I hope this helps.
Teodor
teodord's picture
23026
Joined: Jun 30 2006 - 9:00am
Last seen: 2 weeks 5 days ago

Teodor,

I have the same need. I'm open to implementing (and contributing) a new query executer, but unless I'm missing something, this is a fairly pervasive change as I see no mechanism to pass in the needed context (the parameter map), nor for that matter, any sort of context.

JRXPathExecuterFactory is instantiated by reflection (so it can be cached) and thus you can't pass parameters into the constructor.

Seems to me that you want to inject something that gives access to parameters into the JRXpathExecuter (perhaps the JRDataset).

I'm surprised this feature hasn't been added yet. Basically it seems to me to be the mechanism to allow a single JRXML to be used with multiple record schemas by providing the ability of "mapping" field declarations in the JRXML to fields in the dataset(s).

To put that a different way, I could define a single template for contact data and populate it from a number of different datasources with different record layouts.

I could define my JRXML fields generically: LAST_NAME, FIRST_NAME

and then provide different mappings (via XPATH, SQL field name, etc.) as follows:

For one record format I might map LAST_NAME to "student/name/last"

For another record format I might map LAST_NAME to "contact/last_name".

Can you provide any guidance as to a feasible way to accomplish this? Either via existing mechanisms?

dablick - 9 years 1 month ago
Feedback