0

I have an issue with transforming an xml data by using xslt template. I guess the issue is about the namespace in the xml, after I remove the namespace xmlns="http://schemas.microsoft.com/sharepoint/soap/, everything is working fine.

<?xml version="1.0"?>
<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>
        <GetListCollectionResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
            <GetListCollectionResult>
                <Lists>
                    <List Title="Announcement1" Description="Announcement 1"/>
                    <List Title="Announcement2" Description="Announcement 2"/>
                </Lists>
            </GetListCollectionResult>
        </GetListCollectionResponse>
    </soap:Body>
</soap:Envelope>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="msxsl">

  <xsl:template match="//Lists">
    <table>
      <xsl:for-each select="List">
        <tr>
          <td>
            <xsl:value-of select="@Title"/>:
          </td>
          <td>
            <xsl:value-of select="@Description"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

1 Answer 1

2

Just add a namespace to your stylesheet and it will work fine. Here's your stylesheet with the namespace ms used. You can use whatever prefix you want though:

<xsl:stylesheet version="1.0"
  xmlns:ms="http://schemas.microsoft.com/sharepoint/soap/"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="msxsl ms">

  <xsl:template match="//ms:Lists">
    <table>
      <xsl:for-each select="ms:List">
        <tr>
          <td>
            <xsl:value-of select="@Title"/>:
          </td>
          <td>
            <xsl:value-of select="@Description"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

This produces the following output:

<table><tr><td>Announcement1:
  </td><td>Announcement 1</td></tr><tr><td>Announcement2:
  </td><td>Announcement 2</td></tr></table>

Alternatively, in XSLT 2.0, you can just use an asterisk (*) for the prefix and not add a namespace at all:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="msxsl">

  <xsl:template match="//*:Lists">
    <table>
      <xsl:for-each select="*:List">
        <tr>
          <td>
            <xsl:value-of select="@Title"/>:
          </td>
          <td>
            <xsl:value-of select="@Description"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

This will produce the same output as the previous example.

3
  • xmlns:ms="schemas.microsoft.com/sharepoint/soap" it does help, thanks a lot.
    – Shawn.X
    Commented Oct 22, 2011 at 11:37
  • 1
    @Shawn.X: When it does help, then you must accept the answer. This is how we say "Thank you" at SO. Commented Oct 22, 2011 at 14:35
  • You're very welcome @Shawn.X. Like Dimitre pointed out, please mark my answer accepted. Thanks! Commented Oct 22, 2011 at 20:42

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.