Jump to content

XForms: Transform "input" instance to "output" instance


lacco

Recommended Posts

Hi!I'm just evaluating how XForms can support my web application: I have quite different XML data structures which a user have to manipulate. Sometimes I would like that the user "creates" another data structure with different schema from a given one, and there should be some help for him. I give an example:Input XML:

<auction>  <id>5</id>  <date>01-01-2008</date>  <description>I sell a hair dryer for 10 Dollars.</description></auctionItem>

Output XML:

<auctionItem id="5">  <purchaseDate>01-01-2008</purchaseDate>  <currentPrice>10</currentPrice></auctionItem>

Perhaps you see my problem: As input, a user get a mix between structured (date) and unstructured (description) data, and it should be putted in another XML. The structured data should be automatically filled in, the description should be evaluated by user. How can I handle this use case with XForms?Thanks a lot!

Link to comment
Share on other sites

Unless there's a field where the user explicitly enters "10" (and which in turn gets filled into the initial XForm instance), I don't see any way the price could be extracted from the description. Not intelligently anyway. It could possibly be done if the description is always "I sell a *product* for *price* *currency", but if it could be anything else too, there's no way.

Link to comment
Share on other sites

The user should enter "10", but he shouldn't enter "01-01-2008". The task of the user should be to extract data from an unstructured source, whereas structured data should be just transformed. I have something in mind like this:

<instance id="input1"><auction>  <id>5</id>  <date>01-01-2008</date>  <description>I sell a hair dryer for 10 Dollars.</description></auction></instance><instance id="output"><auctionItem id="5">  <purchaseDate>01-01-2008</purchaseDate>  <currentPrice>10</currentPrice></auctionItem></instance>

And the Form:

Please extract data from auction, ending on <output source="instance('input1')/auction/date" target="instance('output')/auctionItem/purchaseDate"/>: <input ref="instance('output')/auctionsItem/currentPrice"/>

I know, there isn't any source and target attribute, but what can i do, if input XML isn't equivalent to output?

Link to comment
Share on other sites

I think the calculate attribute of bind could be used for my case:

<bind id="date" nodeset="instance('output')/auctionItem/purchaseDate" calculate="instance('input1')/auction/date">

Please extract data from auction, ending on <output bind="date"/>: <input ref="instance('output')/auctionsItem/currentPrice"/>

This seems to be a workaround for transforming one xml structure into another, I'll try it out. If you have a nicer way, plz tell me :).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...