Deleting duplicate ISO19139 keywords using XSLT

As I’ve continued crunching on Minnesota’s metadata for the Big Ten Academic Alliance Geoportal, I inadvertently created some duplicate keywords. I figured there must be a fairly straightforward way to identify (and remove) these duplicates using XSLT. Thanks to Stack Overflow and my ability to kludge XSLT bits together, I came up with the following.

//gmd:keyword[* = preceding-sibling::gmd:keyword/*]

This snippet selects every keyword in the document using //gmd:keyword, but with a condition that the text of any child element (which in ISO19139 metadata can be gco:CharacterString or gmx:Anchor, but that’s getting off track) is equal to the text of the preceding keyword.

Now, I don’t believe this would capture duplicates that don’t follow immediately after each other, but in my case that’s how they are organized, so it works!