I want to copy the attribute node and the parent of the corresponding element node. How do I get the parent of the elementnode of an attribute node? I have a sample XML File:
<?xml version="1.0" encoding="UTF-8"?>
<XML>
<Items ID = 'ID'>
<Item OID='haveit'></Item>
<Item OID='ornot'></Item>
</Items>
</XML>
I want this file to transform to:
<?xml version="1.0" encoding="UTF-8"?>
<XML>
<Items ID = 'ID'>
<Item OID='haveit'></Item>
</Items>
</XML>
What I have so far:
<xsl:stylesheet version="2.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="XML">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="Item[@OID = 'haveit']">
<!-- copy parent with all attributes -->
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
With this I'm able to copy the XML root Element and the Item 'haveit'. What I now need is to copy the Items element with the ID attribute.
No comments:
Post a Comment