0
votes

i am looking forwar for an template that removes anode from xml depending upon the value of a chid node,basically i am having an xml like:

<EventInfo>
    <AssignmentEvent>
        <CreateDateTime>2015-06-02T00:00:00+02:00</CreateDateTime>
    </AssignmentEvent>
    <EstimateEvent>
        <CreateDateTime>2015-06-02T07:38:28.0000000Z</CreateDateTime>
        <CommitDateTime>2015-06-04T14:29:38.0000000Z</CommitDateTime>
        <UploadDateTime>2015-06-04T14:29:39.7651796Z</UploadDateTime>
    </EstimateEvent>
    <OtherEvent>
        <OtherEventType>CalculatedDateTime</OtherEventType>
        <OtherEventDateTime>2015-06-04T14:29:12.0000000Z</OtherEventDateTime>
    </OtherEvent>
    <OtherEvent>
        <OtherEventType>RateDate</OtherEventType>
        <OtherEventDateTime>2015-06-01T00:00:00.0000000Z</OtherEventDateTime>
    </OtherEvent>
    <OtherEvent>
        <OtherEventType>OriginalCommitDateTime</OtherEventType>
        <OtherEventDateTime>2015-06-02T07:42:16.000Z</OtherEventDateTime>
    </OtherEvent>
</EventInfo>

i want an xslt template which removes the other event node along with child nodes in which other event type value is OriginalCommitDateTime.

resultant xml would be like

<EventInfo>
    <AssignmentEvent>
        <CreateDateTime>2015-06-02T00:00:00+02:00</CreateDateTime>
    </AssignmentEvent>
    <EstimateEvent>
        <CreateDateTime>2015-06-02T07:38:28.0000000Z</CreateDateTime>
        <CommitDateTime>2015-06-04T14:29:38.0000000Z</CommitDateTime>
        <UploadDateTime>2015-06-04T14:29:39.7651796Z</UploadDateTime>
    </EstimateEvent>
    <OtherEvent>
        <OtherEventType>CalculatedDateTime</OtherEventType>
        <OtherEventDateTime>2015-06-04T14:29:12.0000000Z</OtherEventDateTime>
    </OtherEvent>
    <OtherEvent>
        <OtherEventType>RateDate</OtherEventType>
        <OtherEventDateTime>2015-06-01T00:00:00.0000000Z</OtherEventDateTime>
    </OtherEvent>
</EventInfo>

i am new to xslt any help would be highly appreciated.

thanks in advance.

1

1 Answers

0
votes

i want an xslt template which removes the other event node along with child nodes in which other event type value is OriginalCommitDateTime.

The standard method to exclude specific nodes is to start with the identity transform template to copy all nodes as the rule, then add an empty template matching the nodes you want to exclude as the exception:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="OtherEvent[OtherEventType='OriginalCommitDateTime']"/>

</xsl:stylesheet>