0

Can someone please tell me what the xslt style sheet needs to be to style this xml file:

<?xml version="1.0" encoding="UTF-8"?>
<BrowseNodeLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
  <OperationRequest>
    <HTTPHeaders>
      <Header Name="UserAgent" Value="Jakarta Commons-HttpClient/3.0.1">
      </Header>
    </HTTPHeaders>
    <RequestId>09ZDHZ7PV71DC7Z168WA</RequestId>
    <Arguments>
      <Argument Name="AssociateTag" Value="xxxxx"></Argument>
      <Argument Name="Service" Value="AWSECommerceService"></Argument>
      <Argument Name="SubscriptionId" Value="yyyyy"></Argument>
      <Argument Name="Signature" Value="zzzzz"></Argument>
      <Argument Name="ResponseGroup" Value="NewReleases"></Argument>
      <Argument Name="Operation" Value="BrowseNodeLookup"></Argument>
      <Argument Name="BrowseNodeId" Value="676410011"></Argument>
      <Argument Name="Timestamp" Value="2012-03-03T16:37:17Z"></Argument>
    </Arguments>
    <RequestProcessingTime>0.0326540470123291</RequestProcessingTime>
  </OperationRequest>
  <BrowseNodes>
    <Request>
      <IsValid>True</IsValid>
      <BrowseNodeLookupRequest>
        <BrowseNodeId>676410011</BrowseNodeId>
        <ResponseGroup>NewReleases</ResponseGroup>
      </BrowseNodeLookupRequest>
    </Request>
    <BrowseNode>
      <BrowseNodeId>676410011</BrowseNodeId>
      <Name>Games</Name>
      <NewReleases>
        <NewRelease>
          <ASIN>B0073POVPK</ASIN>
          <Title>Pokepark 2: Wonders Beyond (Wii)</Title>
        </NewRelease>
        <NewRelease>
          <ASIN>B0076X58XI</ASIN>
          <Title>Back to the Future: The Game (Wii)</Title>
        </NewRelease>
      </NewReleases>
      <TopItemSet>
        <Type>NewReleases</Type>
        <TopItem>
          <ASIN>B0073POVPK</ASIN>
          <Title>Pokepark 2: Wonders Beyond (Wii)</Title>
          <DetailPageURL>http://www.amazon.co.uk/Pokepark-2-Wonders-Beyond-Wii-Nintendo/dp/B0073POVPK%3FSubscriptionId%3D116AQMJ35GESH5XBF1G2%26tag%3Dwii07-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0073POVPK</DetailPageURL>
          <ProductGroup>Video Games</ProductGroup>
        </TopItem>
        <TopItem>
          <ASIN>B0076X58XI</ASIN>
          <Title>Back to the Future: The Game (Wii)</Title>
          <DetailPageURL>http://www.amazon.co.uk/Back-Future-Game-Wii-Nintendo/dp/B0076X58XI%3FSubscriptionId%3D116AQMJ35GESH5XBF1G2%26tag%3Dwii07-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0076X58XI</DetailPageURL>
          <ProductGroup>Video Games</ProductGroup>
        </TopItem>
      </TopItemSet>
    </BrowseNode>
  </BrowseNodes>
</BrowseNodeLookupResponse>

The full file is here - http://www.wiiuser.co.uk/XML_Games_NR1_original.xml

so that it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xml xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
    <root>
        <NewRelease>
            <asin>B0073POVPK</asin>
            <Title>Pokepark 2: Wonders Beyond (Wii)</Title>
        </NewRelease>
        <NewRelease>
            <asin>B0076X58XI</asin>
            <Title>Back to the Future: The Game (Wii)</Title>
        </NewRelease>
    </root>
</xml>

The full output file is here - http://www.wiiuser.co.uk/XML_Games_NR1_styled.xml

I know I'm asking for a lot of help here, and I wouldn't normally ask, but I'm really stuck and have tried for days to get it to work. I'm sure it's pretty straightforward for those who know how to do it but I'm not one of them unfortunately.

Please don't mark me down for asking this.

Thanks in advance for any help offered.

This is the xslt file I was using before Amazon change the schema but now it's not working. Maybe there was a problem with it before but the schema change affected it.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <xml>
      <root>
        <xsl:apply-templates select="aws:BrowseNodeLookupResponse/BrowseNodes/BrowseNode/NewReleases/NewRelease" />
      </root>
    </xml>
  </xsl:template>

  <xsl:template match="aws:NewRelease">
    <NewRelease>
    <asin>
      <xsl:value-of select="aws:ASIN" />
    </asin>
    <Title>
      <xsl:value-of select="aws:Title" />
    </Title>
    </NewRelease>
  </xsl:template>  
</xsl:stylesheet>
Mark_54
  • 1,273
  • 4
  • 15
  • 21
  • It will help if you make smaller versions of the input and desired output and put them directly into your question. The old xsl is small enough that it could already be directly in the question rather than a link. – Don Roby Mar 03 '12 at 17:29

1 Answers1

1

You must specify the namespace on all steps of your xpath in the "select" attribute of the apply-templates:

<xsl:apply-templates select="aws:BrowseNodeLookupResponse/aws:BrowseNodes/aws:BrowseNode/aws:NewReleases/aws:NewRelease"/>
Murray McDonald
  • 631
  • 4
  • 5
  • Thanks Murray. I've tried this before and you are correct it does produce the data I need. However, it doesn't seem to work to style data returned by Amazon. To see this - Firefox 'page source' shows the whole xml file (which I don't want) and IE page source' displays the styled result (with element tags) which I do need, as shown in my question. Seen in a browser they both look the same - lines of data whereas other styled files I generate (successfully) look like a proper xml file. Hope this explains my problem. – Mark_54 Mar 03 '12 at 18:22
  • Ah .. so you are doing a "client-side" transformation in the browser and it's working in MSIE but not firefox. Have you checked out this thread? http://stackoverflow.com/questions/221434/firefox-3-doesnt-apply-my-xslt-stylesheet-but-other-browsers-do – Murray McDonald Mar 03 '12 at 18:29
  • I'll read it now. I'm only doing client-side to check if the stylesheet works. Usually, I call AWS with "&style=..." to style the xml as it's returned. (This works fine for almost all the pages of the sites I have). Incidentally, I am checking the files by saving them and opening in a browser(s) I don't need to do this generally. All other files produced by the calls are properly structured xml. – Mark_54 Mar 03 '12 at 18:38
  • Murray - I've added links to the pre and post transform files above. If you open them in a browser you can see how the output should look. Adding the code you suggested only shows data as I mentioned earlier. I need someone to tell me what to do here as, sadly, I'm about to ditch all the sites I have which use this. – Mark_54 Mar 03 '12 at 18:46
  • If you're not *really* doing client-side transformations, you might be better off using xsltproc to try transforms on command-line. – Don Roby Mar 03 '12 at 18:46
  • When the sites are working there is no client side transformation. Everything is done at the server and files are generated and saved overnight. I'm only using client side to try to debug this problem. Any ideas welcome though. – Mark_54 Mar 03 '12 at 18:53
  • Mark -- try shortening your select in the apply-templates to just this: select="//aws:NewReleases/*" -- is there any simple way I can make the actual API call to Amazon webservices? – Murray McDonald Mar 03 '12 at 19:27
  • Murray - I tried it with no succes I'm afraid. Without all the access keys, and various security ids you can't access AWS. By complete accident I happened to select the 'data string' output by the corrected xslt sheet. It shows that the data actually has surrounding tags. It doesn't have the surrounding it all so something in the style is not working properly. This might be why it isn't diplaying??? – Mark_54 Mar 03 '12 at 19:48
  • Actually the first two lines of a standard xml file are missing: – Mark_54 Mar 03 '12 at 19:54
  • Mark - I've tried the corrected XSLT in both XMlSpy and OXygen and it produces the correct result in both. That's not surprising given it's such a straight forwward transformation. There hase to be something else at play here - can you point me to the AWS documentation for the API call you are making? Also, you mention a change to a schema - do you have any details on that? Finally, does Amazon have some sort of ticketing system you can submit a trouble report on? – Murray McDonald Mar 04 '12 at 16:05
  • Murray - apologies for the delay. It's still not working. Are you saying that XMlSpy and OXygen produce results with the first two lines, and surrounding tags, in place? It does seem to do this when viewing page source in IE but not in FF - even when selecting the browser text, right clicking and selecting 'View Selection Source'. The schema isn't an issue as it just requires a change in the version date to be used. Amazon are dreadful with help. I'm inclined to leave this and to try to find another way of producing the results I need. – Mark_54 Mar 09 '12 at 16:33