开发者

XSLT 1 Distinct select on ancestors

开发者 https://www.devze.com 2023-03-02 22:49 出处:网络
I\'ve had a bit of trouble working out the correct statement to return a unique list of values. The following path is just an example, which is similar to my dilemma.

I've had a bit of trouble working out the correct statement to return a unique list of values. The following path is just an example, which is similar to my dilemma.

/Root/Books/Book/Writers/Writer/Fullname

What would return the unique list of "fullnames", keeping in mind that the assumption here is there are multiple writers for each book and they may be involved in multiple books.

Thanks for your help

Here is an example of the XML document

<Root>
    <Books>
        <Book>
            <Title>Book A</Title>
            <Writers>
                <Writer>Jon Smith</Writer>
                <Writer>Peter Smith</Writer>
            </Writers>
        </Book>
        <Book>开发者_Python百科
            <Title>Book B</Title>
            <Writers>
                <Writer>Jon Smith</Writer>
                <Writer>Peter Smith</Writer>
                <Writer>James Bloggs</Writer>
            </Writers>
        </Book>
        <Book>
            <Title>Book C</Title>
            <Writers>
                <Writer>Bob Peterson</Writer>
                <Writer>Peter Smith</Writer>
                <Writer>James Bloggs</Writer>
            </Writers>
        </Book>
    </Books>
</Root>

What I'd like to return is a list of the different writers.

Jon Smith Peter Smith James Bloggs Bob Peterson.

It's trickier because there are multiple books with multiple writers.


Follow Robert's link and just do the first step of the grouping recipe:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:copy-of select='Root/Books/Book/Writers/Writer[not(preceding::Writer = .)]'/>
</xsl:template>

</xsl:stylesheet>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号