Link to home
Start Free TrialLog in
Avatar of mylesac6
mylesac6Flag for United States of America

asked on

Concatenate two fields in XML

I need to concatenate two fields into one .  I need to get Address2 and Address 3 into the Address2 field. Is there an easy way to do this with XSL
<field name="LINE_1" alias="LINE_1" type="0" size="40" screenviewtype="0">
    <id>13</id>
    <fename>Address 1</fename>
    <key>13Recipient</key>
    <fetype>0</fetype>
    <fesize>35</fesize>
    <category>Recipient</category>
    <fegroup>Address</fegroup>
    <customdefaultvalue>NO</customdefaultvalue>
    <shipmentlevel>.Recipient.Address1</shipmentlevel>
    <packagelevel>.Recipient.Address1</packagelevel>
    </field>
 
    <field name="LINE_2" alias="LINE_2" type="0" size="40" screenviewtype="0">
    <id>14</id>
    <fename>Address 2</fename>
    <key>14Recipient</key>
    <fetype>0</fetype>
    <fesize>35</fesize>
    <category>Recipient</category>
    <fegroup>Address</fegroup>
    <customdefaultvalue>NO</customdefaultvalue>
    <shipmentlevel>.Recipient.Address2</shipmentlevel>
    <packagelevel>.Recipient.Address2</packagelevel>
    </field>
 
    <field name="LINE_3" alias="LINE_3" type="0" size="40" screenviewtype="0">
    <id>15</id>
    <fename>Address 3</fename>
    <key>15Recipient</key>
    <fetype>0</fetype>
    <fesize>35</fesize>
    <category>Recipient</category>
    <fegroup>Address</fegroup>
    <customdefaultvalue>NO</customdefaultvalue>
    <shipmentlevel>.Recipient.Address3</shipmentlevel>
    <packagelevel>.Recipient.Address3</packagelevel>
    </field>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Merging tasks like this are usually done, starting from an identity copy
That is a stylesheet with one template that copies the input exactly to the output.

To that identity copy then a specialisation template is added to do the merging.

Usually a third template is added for removing the merged node from its original location

It is entirely unclear to me what you want. So please give me an example of the output you want.

I have made an example of the three templates mentioned above.
Maybe you can start building from there
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="field[@name = 'LINE_2']/fename">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
            <xsl:apply-templates select="../../field[@name = 'LINE_3']/fename/node()"></xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
 
    <xsl:template match="field[@name = 'LINE_3']"/>
    
    
</xsl:stylesheet>

Open in new window

Avatar of mylesac6

ASKER

Hi Gertone

The XML sample I included populates a form with address information.  The Form does not have an address3 field and the address3 field cannot be added because of business rules. I want to add the address3 info to the address2 info for one field.  I have attached the entire XML file for you to view. Hope this helps to understand what I am looking for.

Thanks
ScriptMedImport.txt
so this is your source.
Please post an example of the expected result
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for delay. It tooka while to get back to this customer to test the solution.

Thank you very much.