我有以下XML:
<RULES>
<TRAP name="trap1" oid=".1.2.3">
<VAR_LIST>
<VAR name="var1" value=".1.2.3.1"/>
<VAR name="var2" value=".1.2.3.2"/>
</VAR_LIST>
</TRAP>
<TRAP name="trap2" oid=".1.2.4">
...
</TRAP>
...
</RULES>
我想生成扁平的摘要,所以我按如下方式迭代它:
for $trap in /RULES/TRAP
for $var in $rule/VAR_LIST/VAR
return (opening-tag-declaration($trap), opening-tag-declaration($var), " ")
我想获得以下输出,但我不知道如何仅提取标签的开放声明......
<TRAP name="trap1" oid=".1.2.3> <VAR name="var1" value=".1.2.3.1"/>
<TRAP name="trap1" oid=".1.2.3> <VAR name="var2" value=".1.2.3.2"/>
<TRAP name="trap2" oid=".1.2.4> ...
...
答案 0 :(得分:2)
以下是定义opening-tag-declaration
的一种方法(改编自FunctX库中的this function):
declare namespace example = "http://example.com";
declare function example:opening-tag-declaration
( $elements as element()* ) as element()* {
for $element in $elements
return element
{node-name($element)}
{$element/@* }
};
答案 1 :(得分:0)
这是我在mgibsonbr回答之前解决此问题的自定义方法:
declare function local:tag($node as node()) as xs:string {
concat(substring-before(fn:serialize($node), ">"), ">")
};