2011-10-31 2 views
1

나는 Umbraco를 사용 중이며 XSLT에 약간의 문제가 있습니다. 내가 루트 아래 또는 nodeC의 아래가 nodeA에서 nodeA에서에서 노드 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 (실행이 느려짐) 상당한 비 효율성을 초래하고 //[] 연산자와 함께 사용할 때 이상하고 반 직관적 인 동작을 보입니다.