XSLT counting elements with a given value

后端 未结 3 766
自闭症患者
自闭症患者 2021-01-01 14:34

I need to count the number of elements in an XML file that have a particular value (to verify uniqueness). The XML file looks like this:

EDIT: I upd

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 14:52

    Your xpath is just a little off:

    count(//Property/long[text()=$parPropId])
    

    Edit: Cerebrus quite rightly points out that the code in your OP (using the implicit value of a node) is absolutely fine for your purposes. In fact, since it's quite likely you want to work with the "Property" node rather than the "long" node, it's probably superior to ask for //Property[long=$parPropId] than the text() xpath, though you could make a case for the latter on readability grounds.

    What can I say, I'm a bit tired today :)

提交回复
热议问题