Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "prefix 'soap' is not defined" in xslt file

Tags:

html

xml

xslt

I am trying to transform a string with xml data (response from a web service). I tried to start simple by just getting the name:

<?xml version="1.0" encoding="utf-8"?>
<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:output method="html" indent="yes"/>

    <xsl:template match="/">
      <table>
        <tr>
          <th>Name</th>
        </tr>
        <xsl:for-each select="soap:Envelope/soap:Body/ABRSearchByABNResponse/ABRPayloadSearchResults/response/legalName/">
          <tr>
            <td>
              <xsl:value-of select="givenName"/>
            </td>      
          </tr>   
      </xsl:for-each>

      </table>
    </xsl:template>
</xsl:stylesheet>

However, I get "prefix 'soap' is not defined", how do I fix this? Thanks.

like image 524
peter Avatar asked Jan 25 '11 14:01

peter


1 Answers

In XSLT any namespace prefix used in an XPath expression must be defined in a corresponding namespace declaration.

This is not the case with your code and hence the error.

Solution:

Declare the soap namespace:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     
 xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
 xmlns:soap="http://soap/envelope/"
>
like image 63
Dimitre Novatchev Avatar answered Oct 20 '22 04:10

Dimitre Novatchev