入力ファイル:XQueryを使用してXMLファイル内のすべての要素と属性の出現をカウントするにはどうすればよいですか?
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="6636551">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">72771KAM3</xref>
<xref type="Non_Fiction" type_id="2">US72771KAM36</xref>
</book_xref>
</master_information>
<book_details>
<price>24.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book_details>
</book>
<book id="119818569">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UL5</xref>
<xref type="Non_Fiction" type_id="2">US070185UL50</xref>
</book_xref>
</master_information>
<book_details>
<price>19.25</price>
<publish_date>2002-11-01</publish_date>
<description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
</book_details>
</book>
<book id="119818568">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UK7</xref>
<xref type="Non_Fiction" type_id="2">US070185UK77</xref>
</book_xref>
</master_information>
<book_details>
<price>5.95</price>
<publish_date>2004-05-01</publish_date>
<description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description>
</book_details>
</book>
<book id="119818567">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UJ0</xref>
<xref type="Non_Fiction" type_id="2">US070185UJ05</xref>
</book_xref>
</master_information>
<book_details>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description>
</book_details>
</book>
</books>
私は、ヘッダーと、単純なカウント機能を作ることができた(FYI - 私は、XQueryに新たなんだ)
let $x := string-join(('xref', count(//book//xref)), ':')
return $x
予想通り、私は、ヘッダーとカウントを取得
xref:8
すべての要素と属性に対して機能するように拡張しようとしましたが、機能しません。明らかに間違っているヘッダーのために$ xを入れます。私が使用できる要素/ attrの名前を取得する関数があります。私は1つを見つけることができませんでした。
for $x in //book
let $c := string-join(($x, count($x)), ':')
return $x
私は、プレフィックスヘッダはコロンとその要素/ attrのカウントが続き、その後、「要素/ ATTRの名前」になりたいです。私は間違って何をしていますか?私は本当にあなたの応答に感謝します。
P.S.この種のものはXSLTでやる方が簡単だと思う人もいるかもしれませんが、できる限りXqueryを使ってすべてのデータクエリを実行したいと思います。私はXQueryがXSLTよりも理解しやすいことがわかりました。なぜなら、私はすでに使い慣れているSQLのようなSQL構造だからです。
let $ doc行がextを検索します。私のシステムの異常なファイルですか?私はファイルのパスに入れようとしましたが、うまくいきませんでした。私は一般的にXMLファイルをBaseX GUIにロードしてからXQueryを実行します。あなたのコードにXMLファイルをロードするためには何が必要ですか?ありがとう! – Fenil
通常の方法でdoc()関数を使用します。 –