【问题标题】:xpath advanced syntax confusionxpath 高级语法混淆
【发布时间】:2012-09-06 16:00:22
【问题描述】:
<xsl:template name="makeDiv">   
    <xsl:when test="descendant::*[Parent][Name]">
    </xsl:when>  
</xsl:template>

某处...

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

有人可以向我解释一下 template-name=makeDiv 的定义以及测试在做什么吗?它是否正在寻找属于ParentCheck 后代的任何节点的属性“Parent”和“Name”?

另外,&lt;xsl:when test="not(descendant::*[SomeAttribute])"&gt; 是什么意思?它是指不是SomeAttribute 的其他子元素吗?

【问题讨论】:

    标签: xml xslt xpath


    【解决方案1】:

    descendant:*[Parent][Name] 表示“任何具有子 'Parent' 元素和 'Name' 元素的后代。

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

    descendant::ParentCheck 表示“任何名为 ParentCheck 的后代”

    i.e. <ParentCheck />
    

    【讨论】:

    • 感谢@Jakrabbit!如果您能帮助我解决 XSL 问题,我将非常感激stackoverflow.com/questions/12289248/…
    • 作为 test 表达式,这两个 XPath 表达式被评估为布尔值,因此它们实际上意味着“是否存在...的任何后代”
    猜你喜欢
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 2023-04-05
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多