Placing a Variable in a Variable

Post Reply
mireille
Member
Posts: 24
Joined: Tue Nov 03, 2015 2:12 pm
Location: Roosendaal - NL

Placing a Variable in a Variable

Post by mireille »

Hello everyone,


I'm trying to read some data from my XML dataset attached to my job-file.

This is the path I need to use to fetch the data:

[Metadata.Text:Path="/dn:Workbook/dn:Worksheet[1]/dn:Table[1]/dn:Row[2]/dn:Cell[1]/dn:Data",Dataset="Xml",Model="XML",Before="_"]

The position of the 2 (.....Row[2]....) needs to be dynamic and needs to be replaced by the number in the JobState variable.

So what I actually want is this:

[Metadata.Text:Path="/dn:Workbook/dn:Worksheet[1]/dn:Table[1]/dn:Row[[Job.JobState]]/dn:Cell[1]/dn:Data",Dataset="Xml",Model="XML",Before="_"]


But Switch doesn't like breaking up the pathcode with an other variable.


Does anaybody has a suggestion to get my variable in there?

An important detail is that we can't use the scriptingmodule, so I have to script it in the normal metadata menu's etc..


Thanks in advance!

Greetings from Holland


:D Mireille
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Placing a Variable in a Variable

Post by jan_suhr »

You can construct the X-Path to go by the tag and attribute value.

Then you are not dependent on the order of the tags, it will go by the attribute.
Screenshot 2017-01-27 16.53.58.jpg
Screenshot 2017-01-27 16.53.58.jpg (37.28 KiB) Viewed 7770 times
Screenshot 2017-01-27 16.54.18.jpg
Screenshot 2017-01-27 16.54.18.jpg (16.65 KiB) Viewed 7770 times
In your example it would be //dn:Row[@your_attribute='attribute_value']


Jan
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

Re: Placing a Variable in a Variable

Post by freddyp »

You can only use a variable within a variable by scripting, but there could potentially be other ways of getting to dn:Row[x]. What Jan writes, for example, is worth investigating but if 'attribute_value' in

Code: Select all

//dn:Row[@your_attribute='attribute_value']
has to come from [Job.JobState] you have the same problem.

XPath has lots of functions and perhaps you can find a solution there. If for example the row you are looking for is the last one, then

Code: Select all

//dn:Row[last()]
would give you the correct one.

And another possibility to avoid having to use Switch scripting could be to use an XSL transformation. 'Could be' because whether this will work depends on what the problem is, and you are shifting the scripting from one environment to another one: you still need to script and if you think Switch scripting is difficult, try XSL :)
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: Placing a Variable in a Variable

Post by cstevens »

It looks like you're using a spreadsheet or csv file that was converted to XML. Getting specific row/column data in this format can be problematic. It might be easier if you can just pull data directly from the original data source.

There are multiple forum threads on pulling data from csv files on these forums that may help, but they typically involve some scripting.
jan_suhr
Advanced member
Posts: 592
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Placing a Variable in a Variable

Post by jan_suhr »

If it is Excel you can maybe use my App, https://appstore.enfocus.com/product/excel-to-xml
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
mireille
Member
Posts: 24
Joined: Tue Nov 03, 2015 2:12 pm
Location: Roosendaal - NL

Re: Placing a Variable in a Variable

Post by mireille »

Hello,

Thanks for all the replies!

It's correct, we are starting from an Excel spreadsheet with all the article details in it for the new order. This document is provided by our customer.
We "clean" it up, so all the important data for the workflow remains in the new file and the redundant stuff is removed. Then we export it to XML and submit it to the flow.

My challenge for reading the variable in a variable is bit stranded, because we have no scripting module :(
But I still found a creative workaround to get the data in the place where we need it. (With a bit of manual preparation of the templates)
I used an XSL transform with a link to the rows and cells. I don't know for sure if all the syntax is correct, but it creates a workable output ;)

And Freddy:
if you think Switch scripting is difficult, try XSL :)

I totally agree on this !!! writing XSL is serious complex matter. But thank you for that suggestion. We have now the output we need to let the documents start running through our special workflow.

Many greetings,
Mireille
Post Reply