View Single Post
  #1 (permalink)  
Old May 24th, 2018, 04:56 AM
Neal Neal is offline
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Copy ALL elements except one

I have an XML file that I need to update using XSLT. The update is on 1 field only (DocumentDestinationPartner). The rest of the XML should remain the same.

Original XML file

HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="">
		<MessageParts xmlns="">

I have tried updating using the following XSLT technique (I ‘borrowed’ from the web). But it doesn’t update the specific field.

XSLT file

HTML Code:
<xsl:stylesheet version="1.0" xmlns:xsl="">
	<!--<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>-->
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<!-- -->
    <!-- Identity template : copy all text nodes, elements and attributes -->
    <xsl:template match="@*|node()">
            <xsl:apply-templates select="@*|node()"/>
    <!-- -->
    <!-- 1. Append '#D' or 'D'-->
	<xsl:template match="DocumentDestinationPartner">
				<xsl:when test="contains(//DocumentDestinationPartner, '#D')">
					<xsl:value-of select="concat(//DocumentDestinationPartner, 'D')"/>
					<xsl:value-of select="concat(//DocumentDestinationPartner, '#D')"/>
	<!-- -->
    <xsl:template match="text()">
		<xsl:value-of select="normalize-space()" />
	<!-- -->

In addition, the following attribute for the 'MessageParts' element is removed from the output (NOTE: it is the same as the Envelope attribute) which I wasn't expecting:

HTML Code:

Can anyone help please?

Thanks in advance,

A Northern Soul

Last edited by Neal; May 24th, 2018 at 05:08 AM..
Reply With Quote