XQuery를 사용하여 도서 ID와 함께 <xref>
개의 데이터 만 추출하려고합니다 (이 글을 처음 사용하는 경우).XQuery를 사용하여 특정 XML 레코드를 추출하고 쉼표로 구분 된 형식으로 출력하는 방법?
<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>
예상 출력 포맷 1 :
<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>
XQuery를 I는 포맷 (1)에 대해 사용하고 :
for$x in //book_xref/xref
return $x
여기
입력 데이터 인 fo에 대한 질문 rmat 1 : 도서 ID를 별도로 포함 시키려고 했으므로 출력에 포함되지만 위에서 언급 한 예상 형식과 일치하지 않습니다. 책 ID를 포맷별로 출력물에 가져 오는 방법은 무엇입니까?
예상 출력 형식 2 (쉼표로 구분) : 형식 2
book_id, xref_type, xref_type_id, xref
6636551, Fiction, 1, 72771KAM3
6636551, Non_Fiction, 2, US72771KAM36
119818569, Fiction, 1, 070185UL5
119818569, Non_Fiction, 2, US070185UL50
etc.
질문 : 어떻게 쉼표 출력이 XQuery를 통해 형식을 구분받을 수 있나요? 그것을 위해 XSLT를 고수해야합니까?
답변 해 주셔서 감사합니다.
'book_xref/xref'는'xref' 요소를 선택합니다. 만약'book' 요소가 필요하면 그것을 선택해야합니다. '// book [.// book_xref/xref]'. –
@MartinHonnen이 응답 해 주셔서 감사합니다. 그렇게하면 생략해야하는' '노드가 여전히 표시됩니다. 단순히 ''내부에 다른 노드가 얼마나 많은지와 관계없이 책 번호와 함께 ''데이터를 원하지만 ''외부에 넣기 만하면됩니다. 내 질문이 이해되기를 바랍니다! –
Fenil
예 : CSV 용. '// book // book_xref/xref/string-join ((ancestor :: book/@ id, @type, @type_id,.), ',')'. –