Structural variation while inserting fragment based on user input

Post here questions and problems related to oXygen frameworks/document types.
afuchs
Posts: 23
Joined: Mon May 19, 2014 11:38 am

Structural variation while inserting fragment based on user input

Post by afuchs »

Hello,
In a framework operation, I am trying to let the user determine the number of children a fragment would have.

For example, take the following fragment:

Code: Select all

<cd>
<artist>Name</artist>
<title>Title</title>
</cd>
I am inserting user input by replacing "Name" and "Title" with ${ask('...',generic,'')}.
Now I want to split the input for artist along the commas so that user input "Robert Plant, Jimmy Page, Eric Clapton" would translate into three separate <artist> elements:

Code: Select all

<cd>
<artist>Robert Plant</artist>
<artist>Jimmy Page</artist>
<artist>Eric Clapton</artist>
<title>Title</title>
</cd>
I tried using xpath_eval with a for loop on tokenize of the ${ask()}, but it brought no output:

Code: Select all

${xpath_eval(for $i in tokenize(${ask('Artists:',generic,'')}) return <artist>$i</artist>)}
I may have made some mistakes in the code, but I may also have misunderstood some limitation.
Is there a way to do what I an trying to do?

Thank you in advance,
Alexey
Radu
Posts: 9213
Joined: Fri Jul 09, 2004 5:18 pm

Re: Structural variation while inserting fragment based on user input

Post by Radu »

HI Alexey,
I managed to make things work with something like this:

Code: Select all

${xpath_eval(for $i in tokenize("${ask('Artists:',generic,'')}") return concat("<artist>", $i, "</artist>"))}
I added quotes in the tokenize function value and I also returned the XML tags as plain text instead of XML nodes.
The xpath_eval was never intended to do such heavy lifting, maybe for more complex actions you can orient yourself towards implementing them in Java or in Javascript like these sample operations:
https://github.com/oxygenxml/javascript ... operations
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
afuchs
Posts: 23
Joined: Mon May 19, 2014 11:38 am

Re: Structural variation while inserting fragment based on user input

Post by afuchs »

Hi Radu,
Thank you, that worked for me (after I added the token (comma) for tokenize, which I had forgotten to include in the code snippet)!
And thank you for the nudge towards JS and J.
Post Reply