I have a xml which is like:
<bookstores>
<bookstore>
<book id="1">
<author>ABC</author>
</book>
<book id="2">
<title>YYY</title>
</book>
</bookstore>
<bookstore>
<book id="3">
<author>ABC</author>
</book>
<book id="4">
<author>DEF</author>
</book>
</bookstore>
<bookstore>
<book id="5">
<price>50</price>
</book>
<book id="6">
<title>ZZZ</title>
</book>
</bookstore>
</bookstores>
I would like to select the first occurrence of the child of 'book' node, or in other words, all unique child node of the 'book' node.
So the output should be like:
author
title
price
I wrote a xslt as:
<xsl:for-each select="bookstores/bookstore/book">
<xsl:if test="count(preceding-sibling::*[1]) = 0">
<xsl:value-of select="local-name(*[1])"/>
</xsl:if>
</xsl:for-each>
It returned me nothing...Could anyone give me some help on this? Thanks!!
UPDATE:
What if I have several 'bookstores' elements in my xml, and I just would like to limit the uniqueness within the context of each 'bookstores' so that even 'author' appears in one 'bookstores', it could still be displayed if it appears in another 'bookstores'?