2011-10-31 3 views
1

私はUmbracoを使用していて、XSLTに問題があります。私はルートの下またはノードCの下にノードAからノードAからノードBを得ることができるようにしたいxslt - 子の下でノードタイプを取得

root 
    nodeA 
     nodeB 
     nodeB 
     nodeB 
    nodeC 
     nodeA 
     nodeB 
     nodeB 
     nodeB 

は、私は次のような構造を持っています。

私は現在、次のようにします。

<xsl:param name="currentPage"/> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*/nodeC" /> 
<xsl:template match="/"> 

<!-- start writing XSLT --> 
    <xsl:for-each select="$siteRoot/ancestor-or-self::*/nodeA/nodeB"> 
    <xsl:if test="string(umbracoNaviHide) != '1'"> 
    <li style="background-image: none;"> 
     <xsl:if test="position() = last()"> 
     <xsl:attribute name="class">no-border</xsl:attribute> 
     </xsl:if> 
      <a> 
       <xsl:attribute name="href"> 
       <xsl:value-of select="umbraco.library:NiceUrl(current()/@id)"/> 
       </xsl:attribute> 
       <xsl:attribute name="style"> 
       text-decoration: none; 
       </xsl:attribute> 
       <xsl:value-of select="./Name" /></a></li> 
    </xsl:if> 
    </xsl:for-each> 
</xsl:template> 
+0

@Dimire - XPathの本は読書リストにあります。 MVC3直後、Entity FrameworkとObjective-C :) –

答えて

1
<xsl:param name="currentPage"/> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*/nodeC" /> 
. . . 
    <xsl:for-each select="$siteRoot/ancestor-or-self::*/nodeA/nodeB"> 

あなたは、XPathに何かを読んで、異なる軸の意味を学ばなければなりません。

$currentPage/*/nodeC[1]/nodeA/nodeB 

:単一のXPath式としてより良い

<xsl:param name="currentPage"/> 
     <xsl:variable name="siteRoot" select="$currentPage/descendant-or-self::nodeC[1]" /> 
    . . . 
    <xsl:for-each select="$siteRoot/nodeA/nodeB"> 

または、:

は、あなたが実際にこのコードの全く逆をしたい、可能な限り使用を避けますXPath descendant::またはdescendant-or-self::軸または//疑似演算子 - t (実行が遅い)重大な非効率性をもたらし、[]オペレータと共に使用すると、//は異常で直観的な動作をします。

関連する問題