Xml export and XSLT

Post Reply
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Xml export and XSLT

Post by LasseThid »

I'm working on a flow where I need to export the data submitted via a Submit point to an xml file for use in a different workflow system.
I added an Export metadata to the flow and that creates an xml file looking like this:

Code: Select all

 <field Id="spMF_6_2">
<tag>Korrketur</tag>
<type>boolean</type>
<value>true</value>
<field-list>
<field Id="spMF_7_2">
<tag>Mailadress kund</tag>
<type>string</type>
<required>true</required>
<value>x.y@domain.com</value>
</field>
<field Id="spMF_8_2">
<tag>Projektledare</tag>
<type>choice</type>
<value>John Doe</value>
</field>
</field-list>
</field>
I have created an XSLT that will transform the data into a more user friendly

Code: Select all

<proof>true</proof>
<customer_mail>x.y@domain.com</customer_mail>
<csr_mail>John Doe</csr_mail>
<next_value>

Is it possible to somehow make <customer_mail> and <csr_mail> child nodes of <proof>?

I.e. to have the xml look like this:

Code: Select all

<proof>true</proof>
	<customer_mail>x.y@domain.com</customer_mail>
	<csr_mail>John Doe</csr_mail>
<next_value>
Currently the XSLT looks like this:

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="/">
        <job>
           ...
           <proof>
                <xsl:value-of select="//value[parent::node()/tag='Korrektur']"/>
            </proof>
            <customer_mail>
                <xsl:value-of select="//value[parent::node()/tag='Mailadress kund']"/>
            </customer_mail>
            <csr_mail>
                <xsl:value-of select="//value[parent::node()/tag='Projektledare']"/>
            </csr_mail>
           ...
        </job>
    </xsl:template>
</xsl:stylesheet>
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Xml export and XSLT

Post by Padawan »

Please note that in your example <customer_mail> and <csr_mail> are not child nodes of <proof>. If they are child nodes, then the xml would look like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<job>
   <proof>true<customer_mail>x.y@domain.com</customer_mail>
      <csr_mail>John Doe</csr_mail>
   </proof>
</job>
This can be done with this xslt code:

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="/">
        <job>
           <proof>
                <xsl:value-of select="/field-list/field[tag='Korrketur']/value"/>
            <customer_mail>
                <xsl:value-of select="/field-list/field[tag='Mailadress kund']/value"/>
            </customer_mail>
            <csr_mail>
                <xsl:value-of select="/field-list/field[tag='Projektledare']/value"/>
            </csr_mail>
            </proof>

        </job>
    </xsl:template>
</xsl:stylesheet>
Some notes:
I tested this in an online XSLT tester, not in Switch. It did not accept "//value[parent::node()/tag='Korrektur']", that's why I changed it to the other notation.

Personally I am not in favor for having a node both have text and child nodes, it makes it less readable in my opinion. In fact, I was even not aware that it was legal XML until I checked that for this question. The technical term is a "mixed content" node. But if your workflow demands it, then I guess you can't avoid it.
LasseThid
Advanced member
Posts: 353
Joined: Tue Mar 03, 2015 2:30 pm
Location: Molndal, Sweden

Re: Xml export and XSLT

Post by LasseThid »

Thanks Padawan.

Yeah, there were a couple of typos in the first xml that I have hence fixed, but unfortunately I forgot to update the extract from the xml... :oops: :lol:

It should read <tag>Korrektur</tag> not <tag>Korrketur</tag>.

My xml skills are about 2 on a scale from 1-10000, but at least you understood what I want to do, which is the important thing... :mrgreen: :mrgreen:

Thanks for showing me how to do this correctly. Much appreciated!!
Enfocus Switch, Enfocus PitStop Server, Enfocus PDF Review, HP SmartStream& Kodak Prinergy with RBA
Offset 72x102, Offset Large Format, Digital Large Format and Digital print.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Xml export and XSLT

Post by Padawan »

You're welcome :)
Post Reply