The Detailed specification of the requirement is, in the Request message there is a field by name IgnoreEmptyElementInd it is of boolean type. If that field is True, need to ignore the empty element fields in the request message and default values like "-111" shd be set as default value found. In Case of false, no need to delete empty elements only if default values are found it shd be notified.
My Input message is
<SampleUpdRq>
<RqUID>00000000-0000-0000-0000-000000000000</RqUID>
<UpdMsgRqHdr>
<ContextRqHdr>
<RsSelURL>111</RsSelURL>
<NetworkTrnData>
<TerminalIdent>a</TerminalIdent>
<Name>111</Name>
</NetworkTrnData>
<ClientApp>
<Org>dweer</Org>
<Name>aaaaaaaaaaaaaaaaaaa</Name>
<Version>112</Version>
<Channel>abc</Channel>
</ClientApp>
</ContextRqHdr>
<IgnoreEmptyElementInd>true</IgnoreEmptyElementInd>
</UpdMsgRqHdr>
<SampleKeys>
<SampleId>aaaaaaaaaaaaaaaaaaa</SampleId>
<AltSampleIdentifiers>
<SampleIdent>
<SampleIdentType>-111</SampleIdentType>
<SampleIdentValue>ttttttt</SampleIdentValue>
</SampleIdent>
<SampleIdentType/>
</AltSampleIdentifiers>
<SampleType>
<SampleTypeValue>MMA</SampleTypeValue>
<SampleTypeSrc>bbc</SampleTypeSrc>
<CommercialSampleType></CommercialSampleType>
</SampleType>
<CommercialSampleType>-111</CommercialSampleType>
<COID>aaaaa</COID>
</SampleKeys>
</SampleUpdRq>
If the value of IgnoreEmptyElementInd is true, then output shd be like
<SampleUpdRq>
<RqUID>00000000-0000-0000-0000-000000000000</RqUID>
<UpdMsgRqHdr>
<ContextRqHdr>
<RsSelURL>111</RsSelURL>
<NetworkTrnData>
<TerminalIdent>a</TerminalIdent>
<Name>111</Name>
</NetworkTrnData>
<ClientApp>
<Org>dweer</Org>
<Name>aaaaaaaaaaaaaaaaaaa</Name>
<Version>112</Version>
<Channel>abc</Channel>
</ClientApp>
</ContextRqHdr>
<IgnoreEmptyElementInd>true</IgnoreEmptyElementInd>
</UpdMsgRqHdr>
<SampleKeys>
<SampleId>aaaaaaaaaaaaaaaaaaa</SampleId>
<AltSampleIdentifiers>
<SampleIdent>
<SampleIdentType>Default Found</SampleIdentType>
<SampleIdentValue>ttttttt</SampleIdentValue>
</SampleIdent>
</AltSampleIdentifiers>
<SampleType>
<SampleTypeValue>MMA</SampleTypeValue>
<SampleTypeSrc>bbc</SampleTypeSrc>
</SampleType>
<CommercialSampleType>Default Found</CommercialSampleType>
<COID>aaaaa</COID>
</SampleKeys>
</SampleUpdRq>
If the value of IgnoreEmptyElementInd is false, then output shd be like
<SampleUpdRq>
<RqUID>00000000-0000-0000-0000-000000000000</RqUID>
<UpdMsgRqHdr>
<ContextRqHdr>
<RsSelURL>111</RsSelURL>
<NetworkTrnData>
<TerminalIdent>a</TerminalIdent>
<Name>111</Name>
</NetworkTrnData>
<ClientApp>
<Org>dweer</Org>
<Name>aaaaaaaaaaaaaaaaaaa</Name>
<Version>112</Version>
<Channel>abc</Channel>
</ClientApp>
</ContextRqHdr>
<IgnoreEmptyElementInd>false</IgnoreEmptyElementInd>
</UpdMsgRqHdr>
<SampleKeys>
<SampleId>aaaaaaaaaaaaaaaaaaa</SampleId>
<AltSampleIdentifiers>
<SampleIdent>
<SampleIdentType>Default Found</SampleIdentType>
<SampleIdentValue>ttttttt</SampleIdentValue>
</SampleIdent>
<SampleIdentType/>
</AltSampleIdentifiers>
<SampleType>
<SampleTypeValue>MMA</SampleTypeValue>
<SampleTypeSrc>bbc</SampleTypeSrc>
<CommercialSampleType/>
</SampleType>
<CommercialSampleType>Default Found</CommercialSampleType>
<COID>aaaaa</COID>
</SampleKeys>
</SampleUpdRq>
I have written XSL like this :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*[not(node())]" />
<xsl:template match="*[. = '-111']">
<xsl:copy>
<xsl:text>Default Found</xsl:text>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Really appreciate the expertise help and sorry for the confusion. Thanks in advance.
version="2.0", do you use an XSLT 2.0 processor? And consider to post a representative XML input sample and the corresponding result you want to create, then we can suggest the right XSLT way of solving that.