XSLT ... I can'f find a (working) find minimum value in XML and set variable
Posted
by
Bob
on Stack Overflow
See other posts from Stack Overflow
or by Bob
Published on 2012-09-07T19:13:33Z
Indexed on
2012/09/08
3:38 UTC
Read the original article
Hit count: 153
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 ....
EDIT: Oddly enough if I run a 2nd instance as MAX_Landed with ascending it returns a value just fine. If I switch the order in the XSLT the first instance will return 'False' and the 2nd will work. Hope I'm making sense .....
Example XML which I can't get formatted to show correctly and in a hurry so you get the gist I hope:
<?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 :
<?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
© Stack Overflow or respective owner