Fellow switchers,
i use switch with xslt to create jobtickets from given XML files. now i want to modify data in that XML in switch then write a new XML with the new data (so replace values inside the XML by the new data from switch).
the xml file is quite big, so i don't feel like loading everything into private data or into a dataset made by switch via switchclient (for example) since then i have to create a new XSLT, which everytime i update the jobticket xslt i also have to update a second XSLT which uses the private data items.
for example:
in the XML there is:
<print duplex="yes" sides_printed="4/4" sides_printed_text="dubbelzijdig full colour" color_space="CMYK" collate="" facing_print="" page_order="" divider_sheet=""/>
if i want to replace the value duplex to "no" and the sides_printed to "4/0" but keep everything else like it is...
How would one go around that, is there a load xml replace value X by Y then export metadata... or anything like that ^^. if things ain't clear let me know. hmm... thinking about it, maybe XSLT 2.0?
thanks in advance.
Kevin
replace xml values with switch values
Re: replace xml values with switch values
I would read the entire XML, replace whatever you want, write back to a new file.
Replace whatever value you want like I do with the lineBreaks over here;
Replace whatever value you want like I do with the lineBreaks over here;
Code: Select all
function jobArrived( s : Switch, job : Job )
{
// Get propertyValue
var privateDataKey = s.getPropertyValue('PrivateData');
// Create file with Windows-1252 coding, needed for certain characters
var readBody = File.read(job.getPath(), "Windows-1252");
// Replace LF with CRLF, Prodist needs CRLF for correct parsing of e.g. addresses
var replaceLineBreak = readBody.replace(/\n/g,"\r\n");
// Put body in private data
job.setPrivateData(privateDataKey, replaceLineBreak);
job.sendToSingle(job.getPath());
}
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
Re: replace xml values with switch values
Sander, thx for the response

i don't really get what is happening in these steps;
1. in this step it loads the complete given XML:?: so i should set my xmlpickup with the name: "PrivateData" or...
2. creates a file
3. replaces the (old str,new str) but with the file just created in step 2 which is new created file so nothing to replace:?:
4. create the new private data, (old data, new data)
5. write the file?
Probably a newbie question... but i can't wrap my head around it. Soz
. don't got it working so hope this clears my confusion.
already big thanks.
Kevin


i don't really get what is happening in these steps;
1. in this step it loads the complete given XML:?: so i should set my xmlpickup with the name: "PrivateData" or...
2. creates a file
3. replaces the (old str,new str) but with the file just created in step 2 which is new created file so nothing to replace:?:
4. create the new private data, (old data, new data)

5. write the file?
Probably a newbie question... but i can't wrap my head around it. Soz

already big thanks.
Kevin
Re: replace xml values with switch values
Haha fair enough. I just copied this script as reference/idea for the replace part.
Just tested and came up with this one.

oldXML input:
newXML output:
Just tested and came up with this one.
Code: Select all
function jobArrived( s : Switch, job : Job )
{
// Read properties
var oldValue1 = s.getPropertyValue('oldValue1');
var newValue1 = s.getPropertyValue('newValue1');
// Read incoming XML
var oldXML = File.read(job.getPath(), "Windows-1252");
// Create new XML
var newXML = job.createPathWithName(job.getName());
// Replace stuff
// These properties can easily be filled via standard Switch properties, see screenshot.
var newXMLcontent = oldXML.replace(oldValue1,newValue1);
// Write new XML
File.write(newXML, newXMLcontent, 'Windows-1252');
// Send newXML to output
job.sendToSingle(newXML);
}

oldXML input:
Code: Select all
<print duplex="yes" sides_printed="4/4" sides_printed_text="dubbelzijdig full colour" color_space="CMYK" collate="" facing_print="" page_order="" divider_sheet=""/>
Code: Select all
<print duplex="yes" sides_printed="Hooray" sides_printed_text="dubbelzijdig full colour" color_space="CMYK" collate="" facing_print="" page_order="" divider_sheet=""/>
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
Re: replace xml values with switch values
I'm not a programmer (i can python a tiny bit) so thats why i asked, i kinda thought it could work the way it was posted
...
but that work likes a charm! thank you very very very much.
So many possibility's.
Thanks alot!

but that work likes a charm! thank you very very very much.
So many possibility's.

Thanks alot!
Re: replace xml values with switch values
If you have the scripting module, the sky is the limit 
Good to know it helped you out!

Good to know it helped you out!
Part of my playground:
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter
- HP Indigo 10k, HP Indigo 7600's (full options), Highcon Euclid III, Zünd S3
- HP Production Pro 6.0.1, HP Production Center 2.5.1 beta, Apogee 9.1, Enfocus Switch 13u1 & PitStop Server 13u2.
Chat: open-automation @ gitter