0

我有以下 XML,我只想要第二个值......我该怎么做?

XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <soap:Body>
        <GetVersionCollectionResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
          <GetVersionCollectionResult>
            <Versions>
              <Version AssignedTo="value" />
              <Version AssignedTo="This value I want to get" />
              <Version AssignedTo="value" />
              <Version AssignedTo="value" />
            </Versions>
          </GetVersionCollectionResult>
        </GetVersionCollectionResponse>
      </soap:Body>
    </soap:Envelope>

获取每个值的 XML 请求 (如何将其更改为仅获取第二个值?)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text" indent="no"></xsl:output>
        <xsl:template name="ShowVariables" match="/" >
            <xsl:for-each select="//*[name()='Version']">
                <xsl:value-of select="@AssignedTo" />
            </xsl:for-each>
        </xsl:template>
</xsl:stylesheet>

在此先感谢您的帮助。

问候,西蒙

4

1 回答 1

1

您还必须在样式表中声明XML 文档中使用的名称空间。

样式表

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:sharepoint="http://schemas.microsoft.com/sharepoint/soap/">

  <xsl:output method="text" indent="no"/>

  <xsl:template match="/">
    <xsl:value-of select="//sharepoint:Version[2]/@AssignedTo"/>
  </xsl:template>
</xsl:stylesheet>

或者,如果您想更精确:

<xsl:value-of select="soap:Envelope/soap:Body/sharepoint:GetVersionCollectionResponse/sharepoint:GetVersionCollectionResult/sharepoint:Versions/sharepoint:Version[2]/@AssignedTo"/>

输出

This value I want to get
于 2013-02-21T08:12:31.263 回答