Check type of node in XSL template

后端 未结 3 1834
忘掉有多难
忘掉有多难 2020-12-10 15:35

Is it possible to check the type of a node I matched with a template inside the same template? In case it is, how can I do it? For example I would like to do something like

3条回答
  •  心在旅途
    2020-12-10 15:42

    A more precise way to determine if the node $node is a root node:

    not(count($node/ancestor::node()))
    

    The expression in TimC's answer tests the type of the current node:

    count(.|/)=1
    

    but isn't applicable in the case when we want to determine the type of a node in a variable -- which may belong to another document -- not to the current document.

    Also, a test for a namespace node:

    count($node | $node/../namespace::*) = count($node/../namespace::*) 
    

提交回复
热议问题