Làm cách nào để ngăn các mục trùng lặp vào danh sách, và sau đó lý tưởng, sắp xếp danh sách đó? Những gì tôi đang làm, là khi thông tin ở một cấp bị thiếu, lấy thông tin từ một cấp độ bên dưới nó, để xây dựng danh sách còn thiếu, ở cấp trên. Hiện nay, tôi có XML tương tự như sau:Làm cách nào để ngăn chặn các bản sao, trong XSL?
<c03 id="ref6488" level="file">
<did>
<unittitle>Clinic Building</unittitle>
<unitdate era="ce" calendar="gregorian">1947</unitdate>
</did>
<c04 id="ref34582" level="file">
<did>
<container label="Box" type="Box">156</container>
<container label="Folder" type="Folder">3</container>
</did>
</c04>
<c04 id="ref6540" level="file">
<did>
<container label="Box" type="Box">156</container>
<unittitle>Contact prints</unittitle>
</did>
</c04>
<c04 id="ref6606" level="file">
<did>
<container label="Box" type="Box">154</container>
<unittitle>Negatives</unittitle>
</did>
</c04>
</c03>
Sau đó tôi áp dụng XSL sau:
<xsl:template match="c03/did">
<xsl:choose>
<xsl:when test="not(container)">
<did>
<!-- If no c03 container item is found, look in the c04 level for one -->
<xsl:if test="../c04/did/container">
<!-- If a c04 container item is found, use the info to build a c03 version -->
<!-- Skip c03 container item, if still no c04 items found -->
<container label="Box" type="Box">
<!-- Build container list -->
<!-- Test for more than one item, and if so, list them, -->
<!-- separated by commas and a space -->
<xsl:for-each select="../c04/did">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:value-of select="container"/>
</xsl:for-each>
</container>
</did>
</xsl:when>
<!-- If there is a c03 container item(s), list it normally -->
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Nhưng tôi nhận được "container" kết quả của
<container label="Box" type="Box">156, 156, 154</container>
khi những gì Tôi muốn là
<container label="Box" type="Box">154, 156</container>
Be thấp là kết quả đầy đủ mà tôi đang cố gắng đạt được:
<c03 id="ref6488" level="file">
<did>
<container label="Box" type="Box">154, 156</container>
<unittitle>Clinic Building</unittitle>
<unitdate era="ce" calendar="gregorian">1947</unitdate>
</did>
<c04 id="ref34582" level="file">
<did>
<container label="Box" type="Box">156</container>
<container label="Folder" type="Folder">3</container>
</did>
</c04>
<c04 id="ref6540" level="file">
<did>
<container label="Box" type="Box">156</container>
<unittitle>Contact prints</unittitle>
</did>
</c04>
<c04 id="ref6606" level="file">
<did>
<container label="Box" type="Box">154</container>
<unittitle>Negatives</unittitle>
</did>
</c04>
</c03>
Cảm ơn bạn đã giúp đỡ!
Câu hỏi Tốt (+1). Xem câu trả lời của tôi cho một giải pháp XSLT 1.0, ngắn hơn là giải pháp XSLT 2.0 hiện đang được chọn. :) –