有没有什么方法可以在Saxon-HE 9.6上多个匹配节点的输出中获取换行符分隔的结果?
我使用名为“ saxon-lint”的包装器:
但我发现的问题是,当我使用路径时,会导致意外的结果。
我收到一个错误信息。
我收到错误提示:
(注:该内容为标题和分割线,无需翻译)
我使用名为“ saxon-lint”的包装器:
#!/bin/bash
java -cp /path/to/saxon9he.jar net.sf.saxon.Query -s:"$2" -qs:"$1" !method=text
示例:
file.xml
(文件名)<house_pet_hazards>
<hazard type="cleanup">
<name>hairballs</name>
<guilty_party species="cat">Dilly</guilty_party>
<guilty_party species="cat">Nameless</guilty_party>
<guilty_party species="cat">Katie</guilty_party>
</hazard>
</house_pet_hazards>
命令行:
$ saxon-lint '/house_pet_hazards/hazard/guilty_party' file.xml
输出:
DillyNamelessKatie
预期输出:
Dilly
Nameless
Katie
编辑
我通过搜索谷歌发现了一个半工作的解决方案,由迈克尔·凯提出,所以我编写了这个包装器:
#!/bin/bash
xpath="$1"
[[ -s $2 ]] && file="$(readlink -f "$2")" || file=/dev/stdin
java -cp saxon9he.jar net.sf.saxon.Query -qs:"for \$x in doc('file://$file')$xpath
return (data(\$x),text{' '})" !method=text
输出:
$ saxon-lint "/house_pet_hazards/hazard/guilty_party" /tmp/file.xml
Dilly
Nameless
Katie
但我发现的问题是,当我使用路径时,会导致意外的结果。
house_pet_hazards/hazard/guilty_party
我收到一个错误信息。
Error on line 1 column 37
XPST0003 XQuery syntax error near #...p/file.xml')house_pet_hazards/#:
expected "return", found name "house_pet_hazards"
Static error(s) in query
或者
./house_pet_hazards/hazard/guilty_party
我收到错误提示:
Error on line 1 column 37
XPST0003 XQuery syntax error near #... doc('file:///tmp/file.xml')./#:
expected "return", found "."
Static error(s) in query
包装器
(注:该内容为标题和分割线,无需翻译)