0

I'm quite new to XSL, and I'm trying to change and merge element. I need to use the XML within InDesign

Before:

<?xml version="1.0" encoding="UTF-8" ?>
<catalog>
   <node>
      <Surname>Smith</Surname>
      <Name>Paul</Name>
      <Address1>New York</Address1>
      <Address2>Los Angeles</Address2>
   </node>
   <node>
      <Surname>White</Surname>
      <Name>John</Name>
      <Address1>San Francisco</Address1>
      <Address2>Miami</Address2>
   </node>
</catalog>

After:

<?xml version="1.0" encoding="UTF-8" ?>
<catalog>
   <node>
      <Name>Paul Smith</Name>
      <Address2>Los Angeles</Address2>
      <Address1>New York</Address1>
   </node>
   <node>
      <Name>John White</Name>
      <Address2>Miami</Address2>
      <Address1>San Francisco</Address1>
   </node>
</catalog>

I don't know how I can achieve this.

Thx for your help

DOK
  • 32,337
  • 7
  • 60
  • 92

1 Answers1

0

This XSLT should do what you need, although it doesn't reorder the Addresses. Do they have to be reordered?

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
    <xsl:apply-templates />
</xsl:template>
<xsl:template match="node">
    <node>
        <xsl:apply-templates select="Name"/>
        <xsl:apply-templates select="Address2"/>
        <xsl:apply-templates select="Address1"/>
    </node>
</xsl:template>
<xsl:template match="Name">
    <Name>
        <xsl:value-of select="."/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="../Surname"/>
    </Name>
</xsl:template>
<xsl:template match="Surname" />
<xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>