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">
<Timestamp>2007-05-03T20:39:57.394Z</Timestamp>
<Ack>Success</Ack>
<Version>509</Version>
<Build>e509_core_Bundled_4538992_R1</Build>
<SearchResultItemArray>
<SearchResultItem>
<Item>

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents"
>

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">
<tr>
<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>
</tr>

Sample Code
PHP sample code for this is attached.

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