2 users online. Create an account or sign in to join them.Users

Search

Been working on this issue for a couple of hours here. I have imported an Amazon API feed, but I can't seem to work with it that well in Symphony. I tried limiting the "Included Elements" in the datasource settings, but was having NO luck with that.

Now, I've got the whole feed appearing in my debug XML, but I still can't do anything except copy the whole thing out. As soon as I try to get more specific with my Xpath, it doesn't work.

I've done a bunch of looking about namespaces, but this doesn't seem to have anything too crazy going on?

Please help! I've done this before with the Twitter API and had no problems! So frustrated!

http://www.pastie.org/3182148

You have to declare the Amazon namespace (from the Amazon XML). It's kind of funny that the namespace must match, but the prefix must not. Try this (which works for me):

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:amazon="http://webservices.amazon.com/AWSECommerceService/2009-03-31"
    extension-element-prefixes="amazon">

<xsl:output encoding="UTF-8" indent="yes" method="xml" />

<xsl:template match="data">
    <data>
        <xsl:apply-templates select="game-individual-amazon"/>
    </data>
</xsl:template>

<xsl:template match="game-individual-amazon">
    <xsl:apply-templates select="amazon:ItemLookupResponse"/>
</xsl:template>

<xsl:template match="amazon:ItemLookupResponse">
    <xsl:apply-templates select="amazon:Items/amazon:Item"/>
</xsl:template>

<xsl:template match="amazon:Items/amazon:Item">
    <xsl:value-of select="amazon:ItemAttributes/amazon:Label"/>
</xsl:template>

</xsl:stylesheet>

(If you think about it, it makes sense, though. Everything inside the Amazon XML has the declared namespace, so you can select the elements using the defined prefix for this namespace.)

[EDIT]: Added extension-element-prefixesand root element for output in example code.

Got it! Thank you so much Michael! That was really bugging me last night. Strange that the xmlns didn't have anything after it. That's I guess what confused me and made me unable to grab stuff out. I had just this at the top of my xsl and it obviously wasn't working:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://webservices.amazon.com/AWSECommerceService/2009-03-31">

Strange that the xmlns didn't have anything after it.

It' weird the way it works, and can be confusing. When a specific node has an xmlns attribute, it just references that node.

I still get mega confused by namespacing in xml.

Strange that the xmlns didn't have anything after it.

The xmlns:alias doesn't matter, what matters is the URL coming after it. If your XML has a global xmlns (one without an alias) you still need to declare that same URL in your XSL document as well and and give it an alias for later use.

<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2009-03-31" />

means that this element and all inside it are in that special namespace http://webservices.amazon.com/AWSECommerceService/2009-03-31. Like Michael said, to reference it you have to assign it in your XSL

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:somealias="http://webservices.amazon.com/AWSECommerceService/2009-03-31">

and then use it

<xsl:apply-templates select="somealias:ItemLookupResponse"/>

While the namespace-URL has no function itself (it doesn't even need to be an URL), it is the only unique identifier for any namespace. The xmlns:alias alias itself is completely interchangeable.

Thanks guys. Very interesting.

You are welcome. That was an interesting exercise. :-)

I'd be interested in knowing that if you added a namespace to the Dynamic XML Datasource, ie. somealias:http://webservices.amazon.com/AWSECommerceService/2009-03-31 and then used //somealias:ItemLookupResponse as the Included Elements if the XML returned would be just what you were after?

Yes, I was able to filter the returned XML once I added a "made-up" namespace to the dynamic datasource! I did still have to keep the namespace in my XSL, and I did still have to use the "amazon" in my statement.

That helped trim down the response quite a bit! Thanks!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details