XPath to exclude certain XML elements? -


i have read many (maybe all) posts on excluding elements in xpath , not working. have no clue why.

let's have following structure:

<root>   <elema>       hello world!   </elema>   <elemb>       awesome!       <elemc>really!</elemc>   </elemb> </root> 

no want elements except elemc.

based on have read, tried following xpath:

option 1:

//*[not(self::elemc)] 

option 2:

//*[not(name()='elemc')] 

option 3:

//*[name()!='elemc'] 

i have no clue why not working, suspect stupid mistake. if exact opposite (i.e. leaving out not or !) xpath correctly selects elemc element.

the result should this:

<root>   <elema>       hello world!   </elema>   <elemb>       awesome!   </elemb> </root> 

xpath selection. want select not exist in xml document.

you need tool such xslt generate xml output document based on input xml document. xslt can generate desired output trivially via identity transformation supplemented simple template suppresses copying of element not want (elemc):

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>     </xsl:copy>   </xsl:template>   <xsl:template match="elemc"/> </xsl:stylesheet> 

xpath alone cannot you.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -