Skip to main content
Published: May 03 2007, 3:50:00 PMUpdated: November 28 2020, 3:40:44 PM

Describes how to handle XSL transforms when the input XML contains namespace references.

XML Namespace in Responses

Results returned from eBay typically include a xmlns="urn:ebay:apis:eBLBaseComponents" component in the response. The presence of this namespace can complicate XSL transforms unless the namespace is handled properly in the XSL.

Sample XML Response :

<?xml version="1.0" encoding="UTF-8" ?>
<GetSearchResultsResponse xmlns="urn:ebay:apis:eBLBaseComponents">

Note the xmlns="urn:ebay:apis:eBLBaseComponents" attribute. Also note that if you remove this namespace attribute from the XML response, a 'simple' XSL transform will work.

Transforming the Response

To transform the XML with the returned namespace in-tact, two things need to be done.

First, add an abbreviation (ebl in this case) for the namespace in the XSL sheet :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"

Second, each XPath reference (at each level) will need the abbreviated namespace prefix (ebl:) in the path :

<xsl:for-each select="ebl:SearchResultItemArray/ebl:SearchResultItem/ebl:Item">
<td><xsl:value-of select="ebl:Title"/></td>
<td><xsl:value-of select="ebl:SellingStatus/ebl:CurrentPrice"/></td>
<td><xsl:value-of select="ebl:ListingDetails/ebl:EndTime"/></td>

Sample Code
PHP sample code for this is attached.

How well did this answer your question?
Answers others found helpful