I have XML file , I want to copy it as it is , but I want to filter some unwanted elements and attributes , for example the following is the original file :
<root>
<e1 att="test1" att2="test2"> Value</e1>
<e2 att="test1" att2="test2"> Value 2 <inner class='i'>inner</inner></e2>
<e3 att="test1" att2="test2"> Value 3</e3>
</root>
After the filtration ( e3 element and att2 attribute have been removed ) :
<root>
<e1 att="test1" > Value</e1>
<e2 att="test1" > Value 2 <inner class='i'>inner</inner></e2>
</root>
Notes:
- I prefer to use ( for-each element instead of apply-templates if that possible )
- I have some problems with xsl:element and xsl:attribute since I could not write the current node name
Thanks
I know you’d prefer to use
for-each, but why not use an identity transform and then override that template with what you don’t want to keep?This stylesheet:
produces: