XSLT challenge
Posted: Tue Dec 04, 2018 10:11 am
I have an interesting challenge where I need to create multiple xml files from an xml file output by Tilia Labs Phoenix.
When Phoenix has created the imposition it will create one pdf per layout and one xml file for the entire job. What I need to do is to create an xml file for each layout, in order to be able to import some of the xml-data for routing purposes in Switch.
The xml I'd like to create looks like this:
The xml from Tilia Labs Phoenix looks like this:
I started looking at an xslt for this and came up with this incorrect attempt:
I know the path [parent::node()/tag=''] is most likely incorrect, but how do I set them up to be correct?
Thanks in advance
When Phoenix has created the imposition it will create one pdf per layout and one xml file for the entire job. What I need to do is to create an xml file for each layout, in order to be able to import some of the xml-data for routing purposes in Switch.
The xml I'd like to create looks like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<job>
<id>P151889Liksidig_Phoenix</id>
<index>1</index>
<press>Inca Giljotin dubbelsidig</press>
<stock>Bestruket Silk Ark 2050x1510 Dubbel</stock>
</job>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<job>
<id>P151889Liksidig_Phoenix</id>
<name></name>
<contact></contact>
<phone></phone>
<client></client>
<notes></notes>
<default-bleed>5mm</default-bleed>
<units>mm</units>
<run-length>9</run-length>
<press-minutes>9.0</press-minutes>
<plate-cost>0.0</plate-cost>
<stock-cost>108.12171173095703</stock-cost>
<press-cost>225.0</press-cost>
<die-cost>0.0</die-cost>
<total-cost>333.1217041015625</total-cost>
<waste>0.1355578601360321</waste>
<sheet-usage>0.9152916669845581</sheet-usage>
<underrun>0.0</underrun>
<overrun>0.05882352963089943</overrun>
<layout-count>2</layout-count>
<layouts>
<layout>
<index>1</index>
<name>Layout 1</name>
<workstyle>Sheetwise</workstyle>
<run-length>7</run-length>
<press-minutes>7.0</press-minutes>
<plates>8</plates>
<plate-cost>0.0</plate-cost>
<stock-cost>84.09466552734375</stock-cost>
<press-cost>175.0</press-cost>
<die-cost>0.0</die-cost>
<total-cost>259.09466552734375</total-cost>
<waste>0.0847083255648613</waste>
<sheet-usage>0.9152916669845581</sheet-usage>
<underrun>0.0</underrun>
<overrun>0.0</overrun>
<product-count>1</product-count>
<random>05407108B0384B0BACC7994794B84FBB</random>
<tool-stats>
<categories>
<category>
<name>Cut</name>
<length>9600.0004mm</length>
</category>
<category>
<name>Crease</name>
<length>0mm</length>
</category>
</categories>
</tool-stats>
<priority-stats>
<priority-stat>
<priority>1</priority>
<sheet-usage>0.91529167</sheet-usage>
</priority-stat>
</priority-stats>
<surfaces>
<surface>
<side>Front</side>
<press>
<name>Inca Giljotin dubbelsidig</name>
<id>2f5867ed-b7f7-4adb-9f0e-3e4906a127c2</id>
</press>
<stock>
<name>Bestruket Silk Ark 2050x1510 Dubbel</name>
<id>7529a9de-9338-4041-854e-52148e2181c9</id>
</stock>
<grade>
<name>250 gsm</name>
<id>0f23186d-2df6-4c36-bbfd-270b6fe3747d</id>
<caliper>0.2mm</caliper>
<weight>250 gsm</weight>
</grade>
<sheet>
<name>2040 x 1510mm None</name>
<id>f86a71f6-7249-41ba-81a8-5ddeedde3f8f</id>
<width>2040mm</width>
<height>1510mm</height>
</sheet>
<inks>
<ink>
<name>Black</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Cyan</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Magenta</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Yellow</name>
<separation>false</separation>
<type>normal</type>
</ink>
</inks>
</surface>
<surface>
<side>Back</side>
<press>
<name>Inca Giljotin dubbelsidig</name>
<id>2f5867ed-b7f7-4adb-9f0e-3e4906a127c2</id>
</press>
<stock>
<name>Bestruket Silk Ark 2050x1510 Dubbel</name>
<id>7529a9de-9338-4041-854e-52148e2181c9</id>
</stock>
<grade>
<name>250 gsm</name>
<id>0f23186d-2df6-4c36-bbfd-270b6fe3747d</id>
<caliper>0.2mm</caliper>
<weight>250 gsm</weight>
</grade>
<sheet>
<name>2040 x 1510mm None</name>
<id>f86a71f6-7249-41ba-81a8-5ddeedde3f8f</id>
<width>2040mm</width>
<height>1510mm</height>
</sheet>
<inks>
<ink>
<name>Black</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Cyan</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Magenta</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Yellow</name>
<separation>false</separation>
<type>normal</type>
</ink>
</inks>
</surface>
</surfaces>
</layout>
<layout>
<index>2</index>
<name>Layout 2</name>
<workstyle>Sheetwise</workstyle>
<run-length>2</run-length>
<press-minutes>2.0</press-minutes>
<plates>8</plates>
<plate-cost>0.0</plate-cost>
<stock-cost>24.02704620361328</stock-cost>
<press-cost>50.0</press-cost>
<die-cost>0.0</die-cost>
<total-cost>74.02704620361328</total-cost>
<waste>0.3135312497615814</waste>
<sheet-usage>0.9152916669845581</sheet-usage>
<underrun>0.0</underrun>
<overrun>0.3333333432674408</overrun>
<product-count>1</product-count>
<random>8D89961A1C7F421A852658F84194437B</random>
<tool-stats>
<categories>
<category>
<name>Cut</name>
<length>9600.0004mm</length>
</category>
<category>
<name>Crease</name>
<length>0mm</length>
</category>
</categories>
</tool-stats>
<priority-stats>
<priority-stat>
<priority>1</priority>
<sheet-usage>0.91529167</sheet-usage>
</priority-stat>
</priority-stats>
<surfaces>
<surface>
<side>Front</side>
<press>
<name>Inca Giljotin dubbelsidig</name>
<id>2f5867ed-b7f7-4adb-9f0e-3e4906a127c2</id>
</press>
<stock>
<name>Bestruket Silk Ark 2050x1510 Dubbel</name>
<id>7529a9de-9338-4041-854e-52148e2181c9</id>
</stock>
<grade>
<name>250 gsm</name>
<id>0f23186d-2df6-4c36-bbfd-270b6fe3747d</id>
<caliper>0.2mm</caliper>
<weight>250 gsm</weight>
</grade>
<sheet>
<name>2040 x 1510mm None</name>
<id>f86a71f6-7249-41ba-81a8-5ddeedde3f8f</id>
<width>2040mm</width>
<height>1510mm</height>
</sheet>
<inks>
<ink>
<name>Black</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Cyan</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Magenta</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Yellow</name>
<separation>false</separation>
<type>normal</type>
</ink>
</inks>
</surface>
<surface>
<side>Back</side>
<press>
<name>Inca Giljotin dubbelsidig</name>
<id>2f5867ed-b7f7-4adb-9f0e-3e4906a127c2</id>
</press>
<stock>
<name>Bestruket Silk Ark 2050x1510 Dubbel</name>
<id>7529a9de-9338-4041-854e-52148e2181c9</id>
</stock>
<grade>
<name>250 gsm</name>
<id>0f23186d-2df6-4c36-bbfd-270b6fe3747d</id>
<caliper>0.2mm</caliper>
<weight>250 gsm</weight>
</grade>
<sheet>
<name>2040 x 1510mm None</name>
<id>f86a71f6-7249-41ba-81a8-5ddeedde3f8f</id>
<width>2040mm</width>
<height>1510mm</height>
</sheet>
<inks>
<ink>
<name>Black</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Cyan</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Magenta</name>
<separation>false</separation>
<type>normal</type>
</ink>
<ink>
<name>Yellow</name>
<separation>false</separation>
<type>normal</type>
</ink>
</inks>
</surface>
</surfaces>
</layout>
</layouts>
<products>
<product>
<name>P151889Liksidig_19_Kampanj_1_19_1000x1400-3.pdf</name>
<index>1</index>
<ordered>3</ordered>
<die-source>_1R2HF_P151889Liksidig_19_Kampanj_1_19_1000x1400-3.pdf</die-source>
<die-path>C:/Users/Admin/AppData/Local/Temp/phoenix-c9ce838b-cd34-4f72-8621-f623c3e516db/P151889Liksidig_Phoenix-5240053241993393231/upload/1/_1R2HF_P151889Liksidig_19_Kampanj_1_19_1000x1400-3.pdf</die-path>
<stock>Bestruket Silk Ark 2050x1510 Dubbel</stock>
<grade>250 gsm</grade>
<grain>None</grain>
<width>1000.0015mm</width>
<height>1399.9986mm</height>
<spacing-type>Uniform</spacing-type>
<priority>1</priority>
<rotation>Any</rotation>
<templates/>
<placed>2</placed>
<total>4</total>
<overrun>1</overrun>
<layouts>
<layout index="2" placed="2"/>
</layouts>
</product>
<product>
<name>P151889Liksidig_19_Kampanj_1_18_1000x1400-14.pdf</name>
<index>2</index>
<ordered>14</ordered>
<die-source>_1R2HE_P151889Liksidig_19_Kampanj_1_18_1000x1400-14.pdf</die-source>
<die-path>C:/Users/Admin/AppData/Local/Temp/phoenix-c9ce838b-cd34-4f72-8621-f623c3e516db/P151889Liksidig_Phoenix-5240053241993393231/upload/2/_1R2HE_P151889Liksidig_19_Kampanj_1_18_1000x1400-14.pdf</die-path>
<stock>Bestruket Silk Ark 2050x1510 Dubbel</stock>
<grade>250 gsm</grade>
<grain>None</grain>
<width>1000.0015mm</width>
<height>1399.9986mm</height>
<spacing-type>Uniform</spacing-type>
<priority>1</priority>
<rotation>Any</rotation>
<templates/>
<placed>2</placed>
<total>14</total>
<overrun>0</overrun>
<layouts>
<layout index="1" placed="2"/>
</layouts>
</product>
</products>
</job>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xls:for-each select="layout">
<job>
<id>
<xsl:value-of select="//value[parent::node()/tag='id']"/>
</id>
<index>
<xsl:value-of select="//value[parent::node()/tag='index']"/>
</index>
<press>
<xsl:value-of select="//value[parent::node()/tag='press/name']"/>
</press>
<stock>
<xsl:value-of select="//value[parent::node()/tag='stock/name']"/>
</stock>
</job>
</xls:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks in advance