Re: split xml based on node name - SOLVED

Post Reply
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Re: split xml based on node name - SOLVED

Post by abonsey »

Hi All,
I'm trying to split an xml into individual orders but cannot get it to split and use the required name. See below for sample xml and xslt

What I'm trying to do is split and save based on "Design Number" ie GC155 but I can't get the XSLT to see that field name.
I believe I'm almost there but cannot see the simple mistake I'm making.

Can you help me out please.

TIA
Andrew

XML
<?xml version="1.0" encoding="UTF-8"?>
<csv entries="37">
<entry num="1">
<field name="Design Number">GC155</field>
<field name="Range">Christmas</field>
<field name="Envelope Colour"></field>
<field name="ize">150x150</field>
<field name="QUANTITY ORDERED">60</field>
<field name="PRINTED"></field>
</entry>

XSLT
<xsl:template match="/csv/entry">
<xsl:result-document method="xml" href="{/field/[@name="Design Number"]/value}.xml">
<xsl:copy-of select="." />
</xsl:result-document>
</xsl:template>
Last edited by abonsey on Thu Oct 04, 2018 10:38 am, edited 1 time in total.
abonsey
Member
Posts: 142
Joined: Fri May 24, 2013 5:10 pm

Re: split xml based on node name - SOLVED

Post by abonsey »

With the help of Enfocus this is now solved.
Below is the correct coding for those that are interested:

You always have to bear in mind where the Xpath pointer is when you use href. The pointer is at /csv/entry, and as “field” is just below “entry” there must be no slash. The slash takes the pointer back to the top of the XML and at that point there is no “field”.

When selecting a specific tag it is immediately followed by [, not /[.

The href is in double quotes, so inside the double quotes you have to use single quotes.

There is no “value” tag below "field"

<xsl:result-document method="xml" href="{field[@name='Design Number']}.xml”>


Andrew
risha
Newbie
Posts: 2
Joined: Mon Mar 18, 2019 9:45 am

Re: split xml based on node name - SOLVED

Post by risha »

Really great information share with us
Post Reply