Skip to content

Instantly share code, notes, and snippets.

@trey8611
Created July 15, 2022 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trey8611/be07ed8c688eaff29ba478a9752b0fc8 to your computer and use it in GitHub Desktop.
Save trey8611/be07ed8c688eaff29ba478a9752b0fc8 to your computer and use it in GitHub Desktop.
[Remove Duplicates via XPath 1.0]

If you have a variations XPath like this:

{variations/variant[*]}
<variations>
  <variant>
    <title>V1</title>
    <color>Red</color>
    <SKU>V1RED</SKU>
  </variant>
  <variant>
    <title>V2</title>
    <color>Red</color>
    <SKU>V2RED</SKU>
  </variant>
</variations>

You can remove the duplicate "Red" one like this:

{variants/variant[not(./color=preceding-sibling::variant/color)]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment