XMLLint --shellクエリの内容を書くには?

XMLLint --shellクエリの内容を書くには?

私はこれをxmllint --shell非常に大きなXMLファイルを調べるために使用しています。目的の結果を返すXPathクエリを作成しましたが、結果を表示して保存するには、cdまず各ノードにアクセスし、write filename.xml毎回検索を実行してインデックスを選択する必要がない場合はどうなりますか?私が望む結果は悪くありませんでしたか?例:

xpath count(/root/entry/subentry[special_id = /root/entry/subentry/special_id])
Object is a Node Set :
Set contains 121 nodes:
cd (/root/entry/subentry[special_id = /root/entry/subentry/special_id])[1]
write node1.xml
cd (/root/entry/subentry[special_id = /root/entry/subentry/special_id])[2]
write node2.xml
cd (/root/entry/subentry[special_id = /root/entry/subentry/special_id])[3]
write node3.xml
...
cd (/root/entry/subentry[special_id = /root/entry/subentry/special_id])[121]
write node121.xml

上記は、私がやっていることとほぼ同じです。cd別々に保存して検索を繰り返すことなく、検索から直接XMLノードをファイルに保存する方法はありますか?それとも、検索結果を維持したり、1つのクエリで位置番号を取得したりする方法はありますか?

ベストアンサー1

これは不可能に見えたのでXSLTを書いた。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

    <xsl:template match="/">
        <root>
            <xsl:for-each select="/root/entry/subentry[special_id = /root/entry/subentry/special_id]">
                <xsl:copy-of select="."/>
            </xsl:for-each>
        </root>
    </xsl:template>
</xsl:stylesheet>

おすすめ記事