Sunday, 19 October 2014

Allow and Remove Elements Using XSLT



I will receive an XML which has variable structure but will have 1 field for sure like



`
<Remove_Elements_List>isInJeopardy</Remove_Elements_List>
`


I should use the content of this Remove elements to identify a tag in the incoming xml and remove it using XSL I should also remove the Remove_Elements_List tag.


This should work regardless of namespace and element depth.


I wrote xslt like





<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output omit-xml-declaration="yes" indent="yes" />

<xsl:variable name="Remove_Elements" select="/Remove_Elements_List"></xsl:variable>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="$Remove_Elements" />
<xsl:template match="Remove_Elements_List" />
</xsl:stylesheet>



and the xml is like





<web:Body xmlns:web="http://webservices.com" xmlns:bean="http://beans.com">

<Remove_Elements_List>isInJeopardy</Remove_Elements_List>

<web:terminateSubscriber>
<web:terminateSubscriberRequest>
<bean:accountNo>4638020</bean:accountNo>
<bean:acctExternalId>46380206</bean:acctExternalId>
<bean:actionCode>1</bean:actionCode>
<bean:annotation1></bean:annotation1>
<bean:annotation2></bean:annotation2>
<bean:annotation3></bean:annotation3>
<bean:changeWho>MyDomain</bean:changeWho>
<bean:disconnectReason>3</bean:disconnectReason>
<bean:emfConfigId>341</bean:emfConfigId>
<bean:equipStatus>1</bean:equipStatus>
<bean:externalId>venkat.com</bean:externalId>
<bean:itemDate>14-Oct-2014</bean:itemDate>
<bean:levelCode>2</bean:levelCode>
<bean:memberType>3</bean:memberType>
<bean:orderData>
<bean:auditTrail></bean:auditTrail>
<bean:changeWho></bean:changeWho>
<bean:departmentId></bean:departmentId>
<bean:elementId></bean:elementId>
<bean:fileId></bean:fileId>
<bean:isInJeopardy></bean:isInJeopardy>
<bean:orderId></bean:orderId>
<bean:orderIdResets></bean:orderIdResets>
<bean:orderRevNo></bean:orderRevNo>
<bean:orderStatus></bean:orderStatus>
<bean:orderUrgency></bean:orderUrgency>
<bean:owner></bean:owner>
<bean:parentMemberType></bean:parentMemberType>
<bean:provGroupId></bean:provGroupId>
<bean:serverId></bean:serverId>
<bean:subscrNo></bean:subscrNo>
<bean:subscrNoResets></bean:subscrNoResets>
<bean:supervisorId></bean:supervisorId>
<bean:technicianId></bean:technicianId>
<bean:trackingId></bean:trackingId>
<bean:trackingIdServ></bean:trackingIdServ>
</bean:orderData>
<bean:subscrNo>205135041</bean:subscrNo>
<bean:subscrNoResets>0</bean:subscrNoResets>
</web:terminateSubscriberRequest>
</web:terminateSubscriber>
</web:Body>



Im new to XSLT and cant figure out whats wrong, can anyone please help.


No comments:

Post a Comment