Marklogic:Xpath使用移除处理指令标签

Marklogic: Xpath using removing processing instruction tag

如何使用 XQuery 删除 xml 中的处理指令标记?

样本XML:

<a>
    <text><?test id="1" loc="start"?><b type="bold">1. </b>
    Security or protection <?test id="1" loc=="end"?><?test id="1" loc="start"?><b type="bold">2.
    </b> Analyse.
    <?test id="1" loc="end"?></text>
  </a>

预期输出:

 <a>
     <text><b type="bold">1. </b> Security or protection <b type="bold">2.
     </b> Analyse.</text>

  </a>

请帮助删除 PI 标签。

像这样的东西应该可以工作:

xquery version "1.0-ml";

declare function local:suppress-pi($nodes) {
  for $node in $nodes
  return
    typeswitch ($node)
    case element() return
      element { fn:node-name($node) } {
        $node/@*,
        local:suppress-pi($node/node())
      }
    case processing-instruction() return ()
    default return $node
};

local:suppress-pi(<a>
    <text><?test id="1" loc="start"?><b type="bold">1. </b>
    Security or protection <?test id="1" loc=="end"?><?test id="1" loc="start"?><b type="bold">2.
    </b> Analyse.
    <?test id="1" loc="end"?></text>
  </a>)

HTH!