在不同的xml XPath中访问信息,并显示多个相同的路径

在不同的xml XPath中访问信息,并显示多个相同的路径,xml,xslt,Xml,Xslt,我是XSLT新手,在从当前示例中提取我想要的所有信息时遇到了一些困难 在下面的示例中,我还对message和notice文本属性感兴趣,正如您所看到的,它也在重复节点。你能帮忙提取这些信息吗 <?xml version="1.0"?><chatTranscript startAt="2016-10-06T09:16:40Z" sessionId="0001GaBYC53D000K"> <newParty userId="007957F616780001" t

我是XSLT新手,在从当前示例中提取我想要的所有信息时遇到了一些困难

在下面的示例中,我还对message和notice文本属性感兴趣,正如您所看到的,它也在重复节点。你能帮忙提取这些信息吗

<?xml version="1.0"?><chatTranscript startAt="2016-10-06T09:16:40Z" sessionId="0001GaBYC53D000K">
    <newParty userId="007957F616780001" timeShift="1" visibility="ALL" eventId="1">
        <userInfo personId="" userNick="John Doe" userType="CLIENT" protocolType="FLEX" timeZoneOffset="120"/>
        <userData>
            <item key="GMSServiceId">5954d184-f89d-4f44-8c0f-a772d458b353</item>
            <item key="IdentifyCreateContact">3</item>
            <item key="MediaType">chat</item><item key="TimeZone">120</item>
            <item key="_data_id">139-e9826bf5-c5a4-40e5-a729-2cbdb4776a43</item>
            <item key="firstName">John</item><item key="first_name">John</item>
            <item key="lastName">Doe</item>
            <item key="last_name">Doe</item>
            <item key="location_lat">37.8197</item>
            <item key="location_long">-122.4786</item>
            <item key="userDisplayName">John Doe</item>
        </userData>
    </newParty>

    <message userId="007957F616780001" timeShift="5" visibility="ALL" eventId="2">
        <msgText msgType="text" treatAs="NORMAL">This is message one.</msgText>
    </message>

    <message userId="007957F616780001" timeShift="5" visibility="ALL" eventId="2">
        <msgText msgType="text" treatAs="NORMAL">This is message two.</msgText>
    </message>

    <notice userId="007957F616780001" timeShift="246" visibility="ALL" eventId="3">
        <noticeText noticeType="USER_CUSTOM">This is notice one.</noticeText>
    </notice>

    <notice userId="007957F616780001" timeShift="246" visibility="ALL" eventId="3">
        <noticeText noticeType="USER_CUSTOM">This is notice two.</noticeText>
    </notice>

    <partyLeft userId="007957F616780001" timeShift="291" visibility="ALL" eventId="4" askerId="007957F616780001">
        <reason code="3">left due to disconnect</reason>
    </partyLeft>

</chatTranscript>
当然,我想将消息文本和通知文本添加到此列表中


我认为目前让我感到困惑的是,这两种情况下的xml结构是不同的,我不知道如何处理第二种情况(用于消息和通知)。

我不确定您希望得到什么,但值得注意的是,模板:

<xsl:template match="/chatTranscript/message[count(*) > 1]">

请在给定的示例中显示您希望得到的确切输出。请更正输入XML?这不是因为它缺少根元素。我正在尝试打印消息,然后是通知,如您的示例所示。您是如何删除谓词的,因为当我删除行及其结尾时,我得到了一个错误。@Harriet谓词是方括号中的部分。是的,我知道-但是xml标记有一个开始和结束标记-当我删除这两个标记时,它不起作用。别担心,我已经成功了。我不知道你在说什么。如果从上面的匹配模式中删除
[count(*)>1]
谓词,您将得到我显示的结果。我没有建议删除任何其他内容-当然没有任何开始或结束标记。
GMSServiceId - 5954d184-f89d-4f44-8c0f-a772d458b353 IdentifyCreateContact: 3 MediaType: chat firstName: John userDisplayName: John Doe
<xsl:template match="/chatTranscript/message[count(*) > 1]">
    GMSServiceId - 5954d184-f89d-4f44-8c0f-a772d458b353
    IdentifyCreateContact: 3
    MediaType: chat
    firstName: John
    userDisplayName: John Doe
Message Text: This is message one.
Message Text: This is message two.