xslt - Get only elements that are not repeating in an XML -


i have scenario xml doc contains nodes repeating. want rid of such nodes. please note not "removing duplicates". want remove entries of nodes occuring more once.

ex xml

<readuserobsresponse>  <userobs>   <obsobjectid>1510</obsobjectid>   <userobjectid>443</userobjectid>  </userobs>  <userobs>   <obsobjectid>540</obsobjectid>   <userobjectid>514</userobjectid>  </userobs>  <userobs>   <obsobjectid>1521</obsobjectid>   <userobjectid>514</userobjectid>  </userobs>  <userobs>   <obsobjectid>547</obsobjectid>   <userobjectid>544</userobjectid>  </userobs> </readuserobsresponse> 

desired output : want remove both entries userobjectid 514

<readuserobsresponse>  <userobs>   <obsobjectid>1510</obsobjectid>   <userobjectid>443</userobjectid>  </userobs>  <userobs>   <obsobjectid>547</obsobjectid>   <userobjectid>544</userobjectid>  </userobs> </readuserobsresponse> 

i've done things, not working. idea count nodes userobjectid current value, put in xsl:if , print nodes. i'm not sure how write snippet.

this need.

it has template userobs elements checks whether there 1 userobs child of parent has same value userobjectid. if entire node copied output.

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">      <xsl:strip-space elements="*"/>     <xsl:output method="xml" indent="yes"/>      <xsl:template match="/readuserobsresponse">         <xsl:copy>             <xsl:apply-templates/>         </xsl:copy>     </xsl:template>      <xsl:template match="userobs">         <xsl:if test="count(../userobs[userobjectid = current()/userobjectid]) = 1">             <xsl:copy-of select="."/>         </xsl:if>     </xsl:template>  </xsl:stylesheet> 

output

<?xml version="1.0" encoding="utf-8"?> <readuserobsresponse>    <userobs>       <obsobjectid>1510</obsobjectid>       <userobjectid>443</userobjectid>    </userobs>    <userobs>       <obsobjectid>547</obsobjectid>       <userobjectid>544</userobjectid>    </userobs> </readuserobsresponse> 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -