Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving Duplicate Elements from my XML file by using an XSLT
    primarykey
    data
    text
    <p>Here is an example where I'd like to remove a duplicate entry if the ID is the same. I'm pulling hits from system 'A' and system 'B'. I want system 'A' to have precedence (i.e., if the ID is a duplicate, remove the element from system 'B'). Here's my example:</p> <p>I am getting this result:</p> <pre><code>&lt;HitList&gt; &lt;Hit System="A" ID="1"/&gt; &lt;Hit System="A" ID="2"/&gt; &lt;Hit System="A" ID="2"/&gt; &lt;Hit System="B" ID="1"/&gt; &lt;Hit System="B" ID="2"/&gt; &lt;Hit System="B" ID="3"/&gt; &lt;Hit System="B" ID="4"/&gt; &lt;/HitList&gt; I want this result (with the duplicates removed): &lt;HitList&gt; &lt;Hit System="A" ID="1"/&gt; &lt;Hit System="A" ID="2"/&gt; &lt;Hit System="B" ID="3"/&gt; &lt;Hit System="B" ID="4"/&gt; &lt;/HitList&gt; </code></pre> <p>Current Code:</p> <pre><code> &lt;xsl:template match="/RetrievePersonSearchDataRequest"&gt; &lt;HitList&gt; &lt;xsl:if test="string(RetrievePersonSearchDataRequest/SystemA/NamecheckResponse/@Status) = string(Succeeded)"&gt; &lt;xsl:for-each select="SystemA/NamecheckResponse/BATCH/ITEMLIST/ITEM/VISQST/NCHITLIST/NCHIT"&gt; &lt;Hit&gt; &lt;xsl:attribute name="System"&gt;&lt;xsl:text&gt;A&lt;/xsl:text&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="PersonID"&gt;&lt;xsl:value-of select="number( REFUSAL/@UID)"/&gt;&lt;/xsl:attribute&gt; &lt;/Hit&gt; &lt;/xsl:for-each&gt; &lt;/xsl:if&gt; &lt;xsl:if test="string(RetrievePersonSearchDataRequest/SystemB/NamecheckResponse/@Status) = string(Succeeded)"&gt; &lt;xsl:for-each select="SystemB/NamecheckResponse/PersonIDSearchResponse/personID"&gt; &lt;Hit&gt; &lt;xsl:attribute name="System"&gt;&lt;xsl:text&gt;B&lt;/xsl:text&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="PersonID"&gt;&lt;xsl:value-of select="number(.)"/&gt;&lt;/xsl:attribute&gt; &lt;/Hit&gt; &lt;/xsl:for-each&gt; &lt;/xsl:if&gt; &lt;/HitList&gt; &lt;/xsl:template&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload