XML Input:
<root> <results> <output> <tag1> <tag2> <tag3> <tag4>2016-03-27T14:27:10.542+03:00</tag4> </tag3> <tag5/> <tag6> <record> <column name="Result">smth</column> </record> </tag6> </tag2> </tag1> </output> </results> <DesiredParentTag UserName="admin" UserId="1" timestamp="2016-03-27T17:06:10.764+03:00"> <DesiredChildTag operation="delete"> <action startInstant="2016-03-30T08:35:00+03:00" id="244078"/> <action startInstant="2016-03-29T08:35:00+03:00" id="244078"/> </DesiredChildTag> <DesiredChildTag operation="insert"> <action id="2" startInstant="2016-03-21T08:35:00+03:00"/> </DesiredChildTag> <DesiredChildTag operation="update"> <action id="222" startInstant="2016-03-21T08:35:00+03:00"/> <action id="45" startInstant="2016-03-21T08:35:00+03:00"/> </actions> </DesiredParentTag> </root> Desired XML OUTPUT:
<DesiredParentTag UserName="admin" UserId="1" timestamp="2016-03-27T17:06:10.764+03:00"> <DesiredChildTag operation="delete"> <action startInstant="2016-03-30T08:35:00+03:00" id="244078"/> <!--excluded duplicate id if operation='delete'--> </DesiredChildTag> <DesiredChildTag operation="insert"> <action id="2" startInstant="2016-03-21T08:35:00+03:00"/> </DesiredChildTag> <DesiredChildTag operation="update"> <action id="222" startInstant="2016-03-21T08:35:00+03:00"/> <action id="45" startInstant="2016-03-21T08:35:00+03:00"/> </actions> </DesiredParentTag> I want to copy all that's under the "DesiredParentTag" and if the operation="delete" to exclude the action tags that have the same id. Everythhing else just regular copy.
My current xsl: (it copies the tags I need and the attributes but doesn't exlucude the duplicates if the attirbute operation='delete')
<xsl:key name="ok" match="DesiredParentTag/DesiredChildTag/action" use="@id"/> <xsl:template match="*"> <xsl:copy-of select="DesiredParentTag[count(key('ok',@id)[1]|.)=1]"/> </xsl:template> </xsl:stylesheet>
No comments:
Post a Comment