XPATH用于组合多个相同的条目

时间:2015-02-08 12:27:43

标签: xml xpath xpath-2.0

这是简单的XML数据。我试图在作者标签下获取LastName。

由于有多位作者,我不知道每个作品中会有多少作者。所以我正在寻找一种方法来连接所有条目与“作者”部分下的标签“LastName”,无论有多少。最好用分隔符分隔。

<?xml version="1.0" encoding="UTF-8"?>
<d>
    <Author />
    <Conference />
    <Domain />
    <Journal />
    <Keyword />
    <Organization />
    <Publication>
        <EndIdx>1</EndIdx>
        <StartIdx>1</StartIdx>
        <TotalItem>112686</TotalItem>
        <Result>
            <Abstract />
            <Author>
                <Affiliation />
                <CitationCount>0</CitationCount>
                <DisplayPhotoURL />
                <FirstName>Jiawei</FirstName>
                <GIndex>0</GIndex>
                <HIndex>0</HIndex>
                <HomepageURL />
                <ID>594572</ID>
                <LastName>Han</LastName>
                <MiddleName />
                <NativeName />
                <PublicationCount>0</PublicationCount>
                <ResearchInterestDomain />
            </Author>
            <Author>
                <Affiliation />
                <CitationCount>0</CitationCount>
                <DisplayPhotoURL />
                <FirstName>Micheline</FirstName>
                <GIndex>0</GIndex>
                <HIndex>0</HIndex>
                <HomepageURL />
                <ID>2331044</ID>
                <LastName>Kamber</LastName>
                <MiddleName />
                <NativeName />
                <PublicationCount>0</PublicationCount>
                <ResearchInterestDomain />
            </Author>
            <CitationContext />
            <CitationCount>5979</CitationCount>
            <Conference />
            <DOI />
            <FullVersionURL />
            <ID>694978</ID>
            <Journal />
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>9033</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>9972</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>22078</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>35009</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>36239</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>38375</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>40483</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>41259</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <Keyword>
                <CitationCount>0</CitationCount>
                <ID>73998</ID>
                <Name />
                <PublicationCount>0</PublicationCount>
            </Keyword>
            <ReferenceCount>160</ReferenceCount>
            <Title>Data Mining: Concepts and Techniques</Title>
            <Type>1</Type>
            <Year>2000</Year>
        </Result>
    </Publication>
    <ResultCode>0</ResultCode>
    <Trend />
    <Version>1.1</Version>
</d>

1 个答案:

答案 0 :(得分:1)

XPath 2.0:

string-join(.//Author/LastName, ', ')

在正确的上下文中运行它,例如每<Publication>