0

I have the following XML and I only want the second value... How can I do this?

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 Request to get each value (how can I change this to only get the second value?)

<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>

Thanks in advance for your help.

Regards, Simon

4
  • Which language do you use? Commented Feb 21, 2013 at 7:55
  • The language that I use is XSLT Commented Feb 21, 2013 at 8:04
  • Try to use this argument match="value[2]" Commented Feb 21, 2013 at 8:07
  • I changed this line "<xsl:template name="ShowVariables" match="/" > " to "<xsl:template name="ShowVariables" match="value[2]" >" but then I do not get back any results... The result is blank... Commented Feb 21, 2013 at 8:15

1 Answer 1

1

You have to declare the namespaces that are in use in your XML document in your stylesheet, too.

Stylesheet

<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>

Or, if you want to be more precise:

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

Output

This value I want to get
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Eero, many many thanks. It works! Do you know a good website/debugger to test such things?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.