XSLT, get node with its ancestors -


i need figure out how extract node ancestors. example, given value of "spine percutaneous interventions" , mapping of

  <mdcategorymapping>       <mdcategory title="cerebrovascular" order="20">          <mdcategory title="endovascular surgical neuroradiology" order="230">             <mdcategory title="aneurysms , subarachnoid hemorrhage" order="2310" />             <mdcategory title="brain arteriovenous malformations" order="2320" />             <mdcategory title="cranial dural arteriovenous shunts" order="2330" />             <mdcategory title="head , neck vascular lesions" order="2340" />             <mdcategory title="pediatric vascular interventions" order="2350" />             <mdcategory title="spine percutaneous interventions" order="2360" />             <mdcategory title="spine vascular interventions" order="2365" />             <mdcategory title="stroke" order="2370" />             <mdcategory title="trauma" order="2380" />             <mdcategory title="tumors" order="2390" />          </mdcategory>       </mdcategory>   </mdcategorymapping> 

i need following result:

<mdcategory title="cerebrovascular" order="20">     <mdcategory title="endovascular surgical neuroradiology" order="230">         <mdcategory title="spine percutaneous interventions" order="2360" />     </mdcategory> </mdcategory> 

of course following gives me lowest level category when $next-cat equals "spine percutaneous interventions".

    <xsl:copy-of select="//enes:metainfo/enes:mdcategorymapping//enes:mdcategory[@title = $next-cat]" /> 

result:

<mdcategory title="spine percutaneous interventions" order="2360" /> 

likewise, when $next-cat equals "cerebrovascular" whole tree child nodes.

how lowest-level node ancestors or top-level node selected child nodes?

if know how select element interested in or elements interested in can select them, select ancestors , make sure templates copy these nodes:

<xsl:stylesheet version="2.0"      xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:param name="next-cat" select="'spine percutaneous interventions'"/>  <xsl:strip-space elements="*"/> <xsl:output indent="yes"/>  <xsl:variable name="selected-cat" select="//mdcategory[@title = $next-cat]"/> <xsl:variable name="subtree" select="$selected-cat/ancestor-or-self::*"/>  <xsl:template match="/">   <xsl:apply-templates select="$subtree[2]"/> </xsl:template>  <xsl:template match="@*">   <xsl:copy/> </xsl:template>  <xsl:template match="*[. intersect $subtree]">   <xsl:copy>     <xsl:apply-templates select="@* , node()[. intersect $subtree]"/>   </xsl:copy> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -