2012-09-06 50 views
1
<xsl:template name="makeDiv"> 
    <xsl:when test="descendant::*[Parent][Name]"> 
    </xsl:when> 
</xsl:template> 

下了線某處...XPath的先進語法混亂

<xsl:if test="descendant::ParentCheck"> 
    <xsl:call-template name="makeDiv"/> 
</xsl:if> 

能有人給我解釋一下模板的名稱= makeDiv定義,什麼測試是幹什麼的?它是否正在尋找屬於ParentCheck的後代的任何節點的屬性「Parent」和「Name」?

另外,<xsl:when test="not(descendant::*[SomeAttribute])">是什麼意思?它是否指其他子元素不是SomeAttribute

回答

3

descendant:*[Parent][Name]的意思是「有一個孩子 '家長' 元素和 '名稱' 元素的任何後代。

i.e. <SomeElement> 
     <Parent/> 
     <Name/> 
    <SomeElement> 

descendant::ParentCheck意味着 「任何命名ParentCheck」

i.e. <ParentCheck /> 
+0

感謝@Jakrabbit後裔!我如果你可以幫助我解決XSL問題,我會非常感激http://stackoverflow.com/questions/12289248/xslt-attribute-node-id-cannot-be-created-after-the-children-of-the-containing – bouncingHippo

+2

作爲'test'表達式,評估這兩個XPath表達式作爲布爾值,所以實際上它們的意思是「*是否存在*任何後裔...」 – LarsH