XSLT - Comparing preceding-sibling's elements with current's node element

前端 未结 1 1381
别跟我提以往
别跟我提以往 2020-12-03 17:18

I have this XML file:


    
        Consorcio W3C
        

        
相关标签:
1条回答
  • 2020-12-03 17:50

    Almost correct.

    <xsl:if test="preceding-sibling::recurso[1]/unidad != unidad">
    </xsl:if>
    

    The :: is for axes, not for moving along a path ("making a location step"). In XPath terminology:

    preceding-sibling::recurso[1]/unidad != unidad
    '''''''''''''''''  ++++++++++ ++++++
                              ###
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
    
    '  = axis name       (optional, defaults to "child")
    +  = node test       (required)
    #  = predicate       (optional, for filtering)
    ~  = location step   (required at least once per select expression)
    

    The [1] is a shorthand for [position()=1].

    The child axis is implicit in a location step, so this

    preceding-sibling::recurso[1]/unidad != unidad
    

    is equivalent to this:

    preceding-sibling::recurso[1]/child::unidad != unidad
    
    0 讨论(0)
提交回复
热议问题