I was wondering how I can organise the XML using XSLT <xsl:stylesheet version="2.0"
Get the first position address tag in /root/body/shipTo/destination/address
and add it to the /root/header/address
, however, some fields must be created, renamed, and insert validation.
<root>
<header>
<address>
<street/>
<street3/>
<phone/>
<Region>
<RegionCoded/>
</Region>
</address>
</header>
<body>
<shipTo>
<destination>
<address>
<street>AAA</street>
<street2>BBB</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>test@t.com</email>
</address>
</destination>
<destination>
<address>
<street>CDA</street>
<street2>YYY</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>test@t.com</email>
</address>
</destination>
<destination>
<address>
<street>PPP</street>
<street2>ZZZ</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>test@t.com</email>
</address>
</destination>
</shipTo>
</body>
</root>
The desired result would be something like the XML below:
<root>
<header>
<address>
<street>AAA</address> <!-- street -->
<name1>BBB</name1> <!-- street2 -->
<street3>123</street3> <!-- street99 -->
<phone>
<mobile>1999999999</mobile> <!-- phone -->
</phone>
<Region> <!-- Region -->
<RegionCoded>00</RegionCoded>
</Region>
<emailFROM>test@t.com</emailFROM> <!-- check if is a valid email -->
<merge>AAA | BBB</merge> <!-- street + street2 -->
</address>
</header>
<body>
<shipTo>
<destination>
<address>
<street>AAA</street>
<street2>BBB</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>test@t.com</email>
</address>
</destination>
<destination>
<address>
<street>CDA</street>
<street2>YYY</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>eee@t.com</email>
</address>
</destination>
<destination>
<address>
<street>PPP</street>
<street2>ZZZ</street2>
<street99>123</street99>
<phone>1999999999</phone>
<Region>
<RegionCoded>00</RegionCoded>
</Region>
<email>t@t.com</email>
</address>
</destination>
</shipTo>
</body>
</root>
There is a validation in the email tag, is it possible to add a regex to validate it?
like: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/