xml - Eliminating duplicate same-level elements in XSLT -
I'm looking to display a list of single-level node names, without duplicates.
Let me have the
& lt; A & gt; & Lt; P & gt; & Lt; C / & gt; & Lt; D / & gt; & Lt; D / & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; E / & gt; & Lt; C / & gt; & Lt; F / & gt; & Lt; / P & gt; & Lt; / A & gt; I want to display C, D, E, F. To get rid of the duplicate siblings from the output, I have found many solutions to the same problem, but I am having trouble in destroying a duplicate "cousin".
A possibility:
& Lt; Xsl: template match = "/" & gt; & Lt ;! - Select all nodes at a certain level - & gt; & Lt; Xsl: variable name = "lvl" select = "key ('kennodes bell level', 3)" /> & Lt ;! - Step through them ... - & gt; & Lt; Xsl: each selection = "$ lvl" & gt; & Lt; Xsl: Select Sort = "Name ()" /> & Lt; Xsl: select variable name = "name" = "name ()" /> & Lt ;! - ... and group them by node names - & gt; & Lt; Xsl: if test = "generate-id () = generate-id ($ lvl [name () = $ name] [1])" & gt; & Lt; Xsl: copy-of select = "." / & Gt; & Lt; / XSL: If & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: Templates & gt; Output for the XML you provided:
& lt; C / & gt; & Lt; D / & gt; & Lt; E / & gt; & Lt; F / & gt;
Comments
Post a Comment