I'd like to eliminate injecting duplicate nodes if they already exist in the XML source file. My current code correctly inserts what I want, but does not check to see if the node already exists.
Here is my original XML file I need to manipulate:
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fields>
<fullName>Data_Check_Comments__c</fullName>
<description>Checking Data for Company</description>
<label>Data Check Comments</label>
</fields>
<fields>
<fullName>My_Test_Obj__c</fullName>
<description>General info about the test object.</description>
<inlineHelpText>This is simply a test object.</inlineHelpText>
<label>My Test Obj</label>
</fields>
</CustomObject>
Here is my desired output XML:
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fields>
<inlineHelpText>fields</inlineHelpText>
<fullName>Data_Check_Comments__c</fullName>
<description>Checking Data for Company</description>
<label>Data Check Comments</label>
</fields>
<fields>
<!--***I don't want this duplicate*** inlineHelpText xmlns="">fields</inlineHelpText-->
<fullName>My_Test_Obj__c</fullName>
<description>General info about the test object.</description>
<inlineHelpText>This is simply a test object.</inlineHelpText>
<label>My Test Obj</label>
</fields>
</CustomObject>
Finally here is my current xlst:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:a="http://soap.sforce.com/2006/04/metadata">
<xsl:template match="a:CustomObject/*">
<xsl:copy>
<xsl:element name="inlineHelpText">
<xsl:value-of select="name(.)"/>
</xsl:element>
<xsl:call-template name="copy-children"/>
</xsl:copy>
</xsl:template>
<xsl:template name="copy-children">
<xsl:copy-of select="./*"/>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>