XPath select certain amount of levels only -


if have xml structure this

 <root>   <sub>     <node />     <node />   </sub>     <sub>       <node />     <sub>   <sub>     <sub>       <node />     </sub>   </sub>   <sub>     <sub>       <sub>         <node />       </sub>       <node />     </sub>   </sub>   <node />   <node /> </root> 

is there xpath syntax select first 3 levels of nodes?

so collect

 <root>   <sub>     <node />     <node />   </sub>     <sub />   <sub>     <sub />   </sub>   <sub>     <sub />   </sub>   <node />   <node /> </root> 

update

just explain i'm doing, i've got asp:treeview, binding asp:xmldatasource, , want tree view go 3 nodes deep. may possible on treeview or xmldatasource control way, xpath seemed obvious

thanks, psy

you can add rule matches below level "does nothing":

<xsl:template match="/*/*/*/*"/> 

so complete example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">   <xsl:output indent="yes"/>   <xsl:template match="node() | @*">     <xsl:copy>       <xsl:apply-templates select="node() | @*"/>     </xsl:copy>   </xsl:template>     <xsl:template match="/*/*/*/*"/>  </xsl:stylesheet> 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -