I’ve search for hours and not found an example that allows for the very first position to be the lowest. I’m getting ‘False’ instead of the value returned ….
Example XML :
<?xml version="1.0"?>
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetLowestOfferListingsForASINResult ASIN="0470067802" status="Success">
<AllOfferListingsConsidered>false</AllOfferListingsConsidered>
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<LowestOfferListings>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>Used</ItemCondition>
<ItemSubcondition>Good</ItemSubcondition>
</Qualifiers>
<Price>
<LandedPrice>
<Amount>15.71</Amount>
</LandedPrice>
</Price>
</LowestOfferListing>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>Used</ItemCondition>
<ItemSubcondition>Good</ItemSubcondition>
</Qualifiers>
<Price>
<LandedPrice>
<Amount>16.71</Amount>
</LandedPrice>
</Price>
</LowestOfferListing>
<LowestOfferListing>
<Qualifiers>
<ItemCondition>Used</ItemCondition>
<ItemSubcondition>Good</ItemSubcondition>
</Qualifiers>
<Price>
<LandedPrice>
<Amount>18.71</Amount>
</LandedPrice>
</Price>
</LowestOfferListing>
</LowestOfferListings>
</Product>
</GetLowestOfferListingsForASINResult>
</GetLowestOfferListingsForASINResponse>
Example XSLT that doesn’t work correctly:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:amz="http://mws.amazonservices.com/schema/Products/2011-10-01" exclude-result-prefixes="amz">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="MIN_Landed">
<xsl:for-each select="//Amount">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="" RECORDS="1" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="DATA" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Min_Landed" TYPE="TEXT"/>
</METADATA>
<RESULTSET>
<xsl:attribute name="FOUND">1</xsl:attribute>
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
<ROW>
<xsl:attribute name="MODID">0</xsl:attribute>
<xsl:attribute name="RECORDID">1</xsl:attribute>
<COL>
<DATA>
<xsl:value-of select="amz:Qualifiers/amz:ItemCondition"/>
</DATA>
</COL>
<COL>
<DATA>
<xsl:value-of select="$MIN_Landed"/>
</DATA>
</COL>
</ROW>
</xsl:for-each>
</RESULTSET>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>
HELP PLEASE!
I really didn’t want to post so much Amazon code but here it is stripped down to a bare bones response
APPARENTLY the order matters ……
Example XSLT that does work:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:amz="http://mws.amazonservices.com/schema/Products/2011-10-01" exclude-result-prefixes="amz">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="MIN_Landed">
<xsl:for-each select="//Amount">
<xsl:sort data-type="number" order="ascending"/>
<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="" RECORDS="1" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="DATA" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Min_Landed" TYPE="TEXT"/>
</METADATA>
<RESULTSET>
<xsl:attribute name="FOUND">1</xsl:attribute>
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
<ROW>
<xsl:attribute name="MODID">0</xsl:attribute>
<xsl:attribute name="RECORDID">1</xsl:attribute>
<COL>
<DATA>
<xsl:value-of select="$MIN_Landed"/>
</DATA>
</COL>
<COL>
<DATA>
<xsl:value-of select="amz:Qualifiers/amz:ItemCondition"/>
</DATA>
</COL>
</ROW>
</xsl:for-each>
</RESULTSET>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>
It pays to show the code you’re actually working with, or at least a facsimile that presents all possible factors, like namespaces. Swap this in:
If this doesn’t fix it, there is a problem external to your xsl. This works against the source you’ve provided.
Archive
Your example doesn’t show where your code sits within your XSL, nor is it clear whether or not every Amount in the source document always sits below one each of a,b,c,d,e,f,Price elements or if there is a root element, and if so, what that is. Your code also doesn’t close the variable tag nor show how the variable is being outputted.
Assuming there is nothing going wrong with any of the above, your ‘order’ attribute should be ascending, since with
position() = '1', you are seeking the node at the top position after sorting. Ascending puts the lowest value first.The following code by itself will output the min value in your source document regardless of the source document structure: