xslt - xsl ancestor-or-self not return result -


i have problem when try for-each every parent of node. have xml this:

<item name="news" id="77">   <items>     <item id="102" />     <item id="103" />           </items> </item>     <item id="86">   <items>     <item id="122">       <items>         <item id="6" />         <item id="9" />       </items>     </item>     <item id="12">       <items>         <item id="13" />         <item id="18" />         <item id="19" />       </items>     </item>   </items> </item> <item name="sitemap" id="88" />        

and in template try this:

<xsl:template name="render"> <xsl:param name="length" /> <xsl:param name="item" />   <xsl:for-each select="ancestor-or-self::item[@id='9']">             code   </xsl:for-each>       <xsl:apply-templates select="*"/> 

help me please if can.

upd:
want menu (if choosed option id=9):

<ul>  <li>77</li>  <li>   86   <ul>    <li>     122     <ul>      <li>6</li>      <li>9</li>     </ul>    </li>    <li>12</li>   </ul>  </li>  <li>88</li> </ul> 

my xslt (i think it) not good:

<xsl:template match="/"> <ul> <xsl:call-template name="render">   <xsl:with-param name="item" select="item[@id='9']" />   <xsl:with-param name="length" select="0" /> </xsl:call-template> </ul> </xsl:template>  <xsl:template name="render">   <xsl:param name="length" />   <xsl:param name="item" />   <xsl:for-each select="$item/ancestor-or-self::item[@id='9']">             <xsl:if test="position()=length">       <xsl:variable name="current" select="." />       <xsl:for-each select="../item">         <xsl:choose>           <xsl:when test=".=current">             <li class="selecteditem">               <p>                 <xsl:value-of select="@id"/>               </p>               <xsl:call-template name="render">                 <xsl:with-param name="length" select="$lenght + 1" />                 <xsl:with-param name="item" select="$item" />               </xsl:call-template>             </li>           </xsl:when>           <xsl:otherwise>             <li>               <p>                 <xsl:value-of select="@id"/>               </p>             </li>           </xsl:otherwise>         </xsl:choose>       </xsl:for-each>     </xsl:if>   </xsl:for-each>       <xsl:apply-templates select="*"/> </xsl:template> 

you haven't made problem clear, wonder if perhaps looking ancestors of parameter node $item, rather ancestors of context node? if so,

select="$item/ancestor-or-self::item[@id='9'] 

however, in sample xml, node @id='9' isn't ancestor of anything, suspect groping in dark.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -