I have a number of XML files containing lots of overhead. I wish to keep only about 20 specific elements and filter out anything else. I know all the names of the elements I
This general transformation:
ns:currency
ns:currency_code3
when applied on the provided XML document (with namespace definition added to make it well-formed):
somecurrency
produces the wanted result (white-listed elements and their structural relations are preserved):
somecurrency
Explanation:
The identity rule/template copies all nodes "as-is".
The stylesheet contains a top-level
element whose
children specify all white-listed element's names -- the elements that are to be preserved with their structural relationships in the document.
The
element is best kept in a separate document so that the current stylesheet will not need to be edited with new names. Here the whitelist is in the same stylesheet just for convenience.
One single template is overriding the identity template. It doesn't process (deletes) any element that is not white-listed and has no descendent that is white-listed.