Jump to content

Set a variable in stylesheet to the first match only


Cabinetman

This topic is 3625 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Oh how I despise XSL sometimes .........

 

Short version :

 

I'm importing multiple offer listings from Amazon and have a working stylesheet. I'm trying to set several variables for each record .... no problem on the others which just pull the first position.

 

Example :

<RESULTSET>
<xsl:attribute name="FOUND">1</xsl:attribute>
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
  <xsl:variable name="MIN_Landed">
    <xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
      <xsl:sort data-type="number" order="ascending"/>
      <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
    </xsl:for-each>
</xsl:variable>

HOWEVER ... In this variable I only want the first match for each condition. This is my test for 'Good'

<RESULTSET>
<xsl:attribute name="FOUND">1</xsl:attribute>
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
   ................ other variables such as MIN_Landed above ...............
   <xsl:variable name="MIN_Condition_Good">
     <xsl:for-each select="..//amz:Qualifiers/amz:ItemSubcondition">
        <xsl:sort data-type="text" order="descending"/>
        <xsl:if test="starts-with(.,'Good')">
            <xsl:value-of select="../..//amz:Price/amz:ListingPrice/amz:Amount[1]"/>
        </xsl:if>
     </xsl:for-each>
</xsl:variable>   

BUT I get ALL matching prices in the import : 0.011.612.03

.... instead of just 0.01

 

I have spent 4 hours now searching the web, reading and testing ....... and I don't think it should be that hard to do !

 

UGH !!

 

Source XML slightly modified due to length :

<?xml version="1.0"?>
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"><GetLowestOfferListingsForASINResult ASIN="B00B9ZH4UY" 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"><Identifiers><MarketplaceASIN><MarketplaceId>ATVPDKIKX0DER</MarketplaceId><ASIN>B00B9ZH4UY</ASIN></MarketplaceASIN></Identifiers><LowestOfferListings><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>VeryGood</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>Unknown</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>3</NumberOfOfferListingsConsidered><SellerFeedbackCount>374897</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>4.00</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>0.01</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Good</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>204537</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>4.00</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>0.01</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Mint</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>Unknown</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>374897</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>4.00</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>0.01</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Mint</ItemSubcondition><FulfillmentChannel>Amazon</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>8410</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.09</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>5.09</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>0.00</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Mint</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>12</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.27</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.28</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Good</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>89910</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.60</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.61</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Acceptable</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>89910</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.60</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.61</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>VeryGood</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>98-100%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>89910</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.60</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.61</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Acceptable</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>Unknown</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>8665</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.83</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.84</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>VeryGood</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>Unknown</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>12302</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.85</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.86</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Mint</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>Unknown</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>18979</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>5.86</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>1.87</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>Good</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>71393</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>6.02</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>2.03</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice></LowestOfferListing><LowestOfferListing><Qualifiers><ItemCondition>Used</ItemCondition><ItemSubcondition>VeryGood</ItemSubcondition><FulfillmentChannel>Merchant</FulfillmentChannel><ShipsDomestically>True</ShipsDomestically><ShippingTime><Max>0-2 days</Max></ShippingTime><SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating></Qualifiers><NumberOfOfferListingsConsidered>1</NumberOfOfferListingsConsidered><SellerFeedbackCount>71393</SellerFeedbackCount><Price><LandedPrice><CurrencyCode>USD</CurrencyCode><Amount>6.09</Amount></LandedPrice><ListingPrice><CurrencyCode>USD</CurrencyCode><Amount>2.10</Amount></ListingPrice><Shipping><CurrencyCode>USD</CurrencyCode><Amount>3.99</Amount></Shipping></Price><MultipleOffersAtLowestPrice>Unknown</MultipleOffersAtLowestPrice></LowestOfferListing></LowestOfferListings></Product></GetLowestOfferListingsForASINResult></GetLowestOfferListingsForASINResponse>
Link to comment
Share on other sites

This part:

<xsl:for-each select="..//amz:Qualifiers/amz:ItemSubcondition">
        <xsl:sort data-type="text" order="descending"/>
        <xsl:if test="starts-with(.,'Good')">
            <xsl:value-of select="../..//amz:Price/amz:ListingPrice/amz:Amount[1]"/>
        </xsl:if>
</xsl:for-each>

looks at all <ItemSubcondition> elements that start with 'Good" (not sure why you need to sort them, if you're picking only the 'Good' ones) and returns the value of the (first) corresponding <Amount> for each one of them. The "first" predicate seems to be redundant, since my test shows there's only one such <Amount>.

 

The logic of what you're trying to do escapes me. What is so special about the "0.01" <Amount>? It just happens to be the one that corresponds to the first 'Good' <ItemSubcondition>. And "first" here is in document order - which is not likely to be significant.

Link to comment
Share on other sites

This part:

<xsl:for-each select="..//amz:Qualifiers/amz:ItemSubcondition">
        <xsl:sort data-type="text" order="descending"/>
        <xsl:if test="starts-with(.,'Good')">
            <xsl:value-of select="../..//amz:Price/amz:ListingPrice/amz:Amount[1]"/>
        </xsl:if>
</xsl:for-each>

looks at all <ItemSubcondition> elements that start with 'Good" (not sure why you need to sort them, if you're picking only the 'Good' ones)

 

It's quite possible I don't need to ... so I removed it. Same result though.

 

 

and returns the value of the (first) corresponding <Amount> for each one of them. The "first" predicate seems to be redundant, since my test shows there's only one such <Amount>.

 

The logic of what you're trying to do escapes me. What is so special about the "0.01" <Amount>? It just happens to be the one that corresponds to the first 'Good' <ItemSubcondition>. And "first" here is in document order - which is not likely to be significant.

 

There are 3 'Good' LowestOfferListing's in the XML response. I only want the lowest ... which will appear first to go into the variable.

 

After I figure it out I'll create variables for Acceptable, VeryGood and Like New.

 

I want each imported record to show the lowest price for each condition ............

Link to comment
Share on other sites

There are 3 'Good' LowestOfferListing's in the XML response. I only want the lowest ... which will appear first to go into the variable.

 

I believe this could be achieved by:

<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']/amz:Price/amz:ListingPrice/amz:Amount">
    <xsl:sort data-type="number" order="ascending"/>
    <xsl:if test="position()=1">
        <xsl:value-of select="."/>
    </xsl:if>
</xsl:for-each>
Link to comment
Share on other sites

Thanks ............ it took me a bit to figure out why it was blank at first but I got it.

 

Where the variable was I was already inside a for-each so your for-each was empty.

 

I moved it further up the XSL and above the other variables and the first for-each and it stated working .........

 

i.e.

<RESULTSET>
	<xsl:attribute name="FOUND">1</xsl:attribute>
	<xsl:variable name="MIN_Condition_Good">
		<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']/amz:Price/amz:ListingPrice/amz:Amount">
 			<xsl:sort data-type="number" order="ascending"/>
    			<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
		</xsl:for-each>
	</xsl:variable>	
	<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
		<xsl:variable name="MIN_Landed">
			<xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
				<xsl:sort data-type="number" order="ascending"/>
					<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
			</xsl:for-each>
		</xsl:variable>
		<xsl:variable name="MAX_Landed">
		.................................................etc ...........................
Link to comment
Share on other sites

 

Where the variable was I was already inside a for-each so your for-each was empty.

 

 

 

 

Yeah, well ... so now you understand (B):

 

It's difficult to figure out what's wrong without (a) seeing the source XML and (B) knowing the current context of your XSLT when declaring the variable.

Link to comment
Share on other sites

Point taken ............ I stand corrected. My apologies.

 

Attached is a full response ..... about 122 records for import .... which is for about 15 ASINs (GetLowestOfferListingsForASINResult's) as called and the returned Amazon response.

 

In theory if each ASIN (GetLowestOfferListingsForASINResult) has at least 1 'Good' offer then during import I should also have 15 different values for the variable MIN_Condition_Good as it goes through the GetLowestOfferListingsForASINResult(s). I did have this with my code before but all matching 'Good' per GetLowestOfferListingsForASINResult were grouped together instead of just the first matching 'Good' in each GetLowestOfferListingsForASINResult.

 

I'm working on it but the issue(s) seems to be that when I backed out of the for-each I was in :

  1. I only get the first match for the entire XML doc. I know due to not including the entire XML doc.
  2. For 'Acceptable' it's skipping ahead past the first match of 1.61 to a later GetLowestOfferListingsForASINResult of 0.67 which is the first match in  GetLowestOfferListingsForASINResult #6

 

This may not be exactly cocrect in style but here's my latest Stylesheet :

<?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" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd" exclude-result-prefixes="amz ns2">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
	<xsl:template match="/">
	<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="MIN_Landed" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MAX_Landed" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MAX_ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Acceptable" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Good" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_VeryGood" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_LikeNew" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ASIN" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ItemCondition" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ItemSubcondition" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="FulfillmentChannel" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ShipsDomestically" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ShippingTimeMax" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SellerPositiveFeedbackRating" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="NumberOfOfferListingsConsidered" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SellerFeedbackCount" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="LandedPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Shipping" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MultipleOffersAtLowestPrice" TYPE="TEXT"/>
			</METADATA>
			<RESULTSET>
				<xsl:attribute name="FOUND">1</xsl:attribute>
				<xsl:variable name="MIN_Condition_Acceptable">
						<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Acceptable']/amz:Price/amz:ListingPrice/amz:Amount">
 							<xsl:sort data-type="number" order="ascending"/>
    						<xsl:if test="position()=1">
        						<xsl:value-of select="."/>
    						</xsl:if>
						</xsl:for-each>
					</xsl:variable>
				<xsl:variable name="MIN_Condition_Good">
						<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']/amz:Price/amz:ListingPrice/amz:Amount">
 							<xsl:sort data-type="number" order="ascending"/>
    						<xsl:if test="position()=1">
        						<xsl:value-of select="."/>
    						</xsl:if>
						</xsl:for-each>
					</xsl:variable>
				<xsl:variable name="MIN_Condition_VeryGood">
						<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='VeryGood']/amz:Price/amz:ListingPrice/amz:Amount">
 							<xsl:sort data-type="number" order="ascending"/>
    						<xsl:if test="position()=1">
        						<xsl:value-of select="."/>
    						</xsl:if>
						</xsl:for-each>
					</xsl:variable>
				<xsl:variable name="MIN_Condition_LikeNew">
						<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Mint']/amz:Price/amz:ListingPrice/amz:Amount">
 							<xsl:sort data-type="number" order="ascending"/>
    						<xsl:if test="position()=1">
        						<xsl:value-of select="."/>
    						</xsl:if>
						</xsl:for-each>
					</xsl:variable>				
				<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
					<xsl:variable name="MIN_Landed">
						<xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
							<xsl:sort data-type="number" order="ascending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MAX_Landed">
						<xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
							<xsl:sort data-type="number" order="descending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MIN_Listing">
						<xsl:for-each select="..//amz:Price/amz:ListingPrice/amz:Amount">
							<xsl:sort data-type="number" order="ascending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MAX_Listing">
						<xsl:for-each select="..//amz:Price/amz:ListingPrice/amz:Amount">
							<xsl:sort data-type="number" order="descending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<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="$MAX_Landed"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Listing"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MAX_Listing"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition_Acceptable"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition_Good"/>
							</DATA>
						</COL>						
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition_VeryGood"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition_LikeNew"/>
							</DATA>
						</COL>
						<COL>						
							<DATA>
								<xsl:value-of select="../../amz:Identifiers/amz:MarketplaceASIN/amz:ASIN"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ItemCondition"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ItemSubcondition"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:FulfillmentChannel"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ShipsDomestically"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ShippingTime/amz:Max"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:SellerPositiveFeedbackRating"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:NumberOfOfferListingsConsidered"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:SellerFeedbackCount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:LandedPrice/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:Shipping/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:MultipleOffersAtLowestPrice"/>
							</DATA>
						</COL>
					</ROW>
				</xsl:for-each>
			</RESULTSET>
		</FMPXMLRESULT>
	</xsl:template>
</xsl:stylesheet>

GetLowestOfferListings_ASIN.xml

Link to comment
Share on other sites

I don't see why you need all those variables; they seem to repeat the same "find" over and over. IIUC, you need to create a record for each result:

<RESULTSET FOUND="">
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult">
    <ROW MODID="" RECORDID="">
     ...

Then, within this result, find the "Good" listings:

<COL><DATA>
   <xsl:for-each select="amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']">
   ...

sort them by price:

      <xsl:sort select="amz:Price/amz:ListingPrice/amz:Amount" data-type="number" order="ascending"/>

and output the value of the first one:

      <xsl:if test="position()=1">
         <xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/>
      </xsl:if>        
   </xsl:for-each>
</DATA></COL>

Repeat for the other conditions.

Link to comment
Share on other sites

I realize you don't see why I do but I do want all those variables.

 

Creating a separate record of each lowest offer of 'Acceptable', 'Good', 'VeryGood' and 'Mint' is not the desired result.

 

Having them all on each OfferListing is ......

 

I'm playing with this but not getting any results.

 

Maybe my explanation isn't up to par.

 

Example :

15 responses with roughly 10 offers each (122 actual total OfferListings though)

EACH OfferListing will have the lowest of each grade for each group (GetLowestOfferListingsForASINResult by ASIN) imported just as it does currently for the MIN_Landed/MAX_Landed and MIN_Listing/MAX_Listing

 

My first posted variable was close but it had ALL of the 'Good' for EACH GetLowestOfferListingsForASINResult all in the variable together.

 

The first GetLowestOfferListingsForASINResult had 3 'Good' OfferListings and all 3 appeared in the field for import ..... instead of just the first one.

 

This is where I stated which worked as planned for each OfferListing. I just want to add in a few more variables and have them appear on EACH OfferListing ....

<?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" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd" exclude-result-prefixes="amz ns2">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
	<xsl:template match="/">
	<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="MIN_Landed" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MAX_Landed" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MAX_ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ASIN" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ItemCondition" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ItemSubcondition" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="FulfillmentChannel" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ShipsDomestically" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ShippingTimeMax" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SellerPositiveFeedbackRating" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="NumberOfOfferListingsConsidered" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="SellerFeedbackCount" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="LandedPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ListingPrice" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Shipping" TYPE="TEXT"/>
				<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MultipleOffersAtLowestPrice" 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">
					<xsl:variable name="MIN_Landed">
						<xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
							<xsl:sort data-type="number" order="ascending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MAX_Landed">
						<xsl:for-each select="..//amz:Price/amz:LandedPrice/amz:Amount">
							<xsl:sort data-type="number" order="descending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MIN_Listing">
						<xsl:for-each select="..//amz:Price/amz:ListingPrice/amz:Amount">
							<xsl:sort data-type="number" order="ascending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<xsl:variable name="MAX_Listing">
						<xsl:for-each select="..//amz:Price/amz:ListingPrice/amz:Amount">
							<xsl:sort data-type="number" order="descending"/>
							<xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
						</xsl:for-each>
					</xsl:variable>			
					<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="$MAX_Landed"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Listing"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MAX_Listing"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="$MIN_Condition_Good"/>
							</DATA>
						</COL>						
						<COL>						
							<DATA>
								<xsl:value-of select="../../amz:Identifiers/amz:MarketplaceASIN/amz:ASIN"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ItemCondition"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ItemSubcondition"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:FulfillmentChannel"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ShipsDomestically"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:ShippingTime/amz:Max"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Qualifiers/amz:SellerPositiveFeedbackRating"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:NumberOfOfferListingsConsidered"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:SellerFeedbackCount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:LandedPrice/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:Price/amz:Shipping/amz:Amount"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="amz:MultipleOffersAtLowestPrice"/>
							</DATA>
						</COL>
					</ROW>
				</xsl:for-each>
			</RESULTSET>
		</FMPXMLRESULT>
	</xsl:template>
</xsl:stylesheet>
Link to comment
Share on other sites

Creating a separate record of each lowest offer of 'Acceptable', 'Good', 'VeryGood' and 'Mint' is not the desired result.

 

Yes, I have noticed that. And although I think it should be the desired result, I haven't brought this up and went with your method of creating a field for each. I am not sure why you bring this up - there is nothing in my suggestion to contradict it. The "Good" offers create a COL in the current ROW. All you need to do is create more COLs and modify the predicate:

[amz:Qualifiers/amz:ItemSubcondition='Good']

to pick another condition type.

Link to comment
Share on other sites

Yes, I have noticed that. And although I think it should be the desired result, I haven't brought this up and went with your method of creating a field for each. I am not sure why you bring this up - there is nothing in my suggestion to contradict it.

Maybe not ... it just seemed so to me with my minimal stylesheet experience.

 

I guess I just can't figure out how to edit my working as desired and returning each OfferListing XSL which is already in a for-each of :

<RESULTSET>
                <xsl:attribute name="FOUND">1</xsl:attribute>
                <xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult/amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">

..... to work with what you suggested of :

<RESULTSET FOUND="">
               <xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult">

Although I am trying. I've tried many variations on where to put what .......

 

Hopefully I'll figure it out tonight.

Link to comment
Share on other sites

I guess I just can't figure out how to edit my working as desired

 

Actually, I can't do that either. But I can suggest how to approach this in a (more) straightforward manner, starting from scratch.

 

Here's a minimal stylesheet that imports just two fields:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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="/">

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

<METADATA>
    <FIELD NAME="ASIN" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="MIN_Condition_Good" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
</METADATA>

<RESULTSET FOUND="">
<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult">
<ROW MODID="" RECORDID="">
    <COL><DATA><xsl:value-of select="@ASIN"/></DATA></COL>
    
    <COL><DATA>
        <xsl:for-each select="amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']">
            <xsl:sort select="amz:Price/amz:ListingPrice/amz:Amount" data-type="number" order="ascending"/>
            <xsl:if test="position()=1">
                <xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/>
            </xsl:if>        
        </xsl:for-each>
    </DATA></COL>
    
</ROW>
</xsl:for-each>

</RESULTSET>
</FMPXMLRESULT>

</xsl:template>
</xsl:stylesheet>

If you duplicate the COL representing the MIN_Condition_Good field and change the predicate from 'Good' to another condition, you'll be just about  done, I think.

  • Like 1
Link to comment
Share on other sites

Thanks ..... but unfortunately that doesn't do what I need.

 

Okay, can you explain why not? Earlier you said:

 

 

I want each imported record to show the lowest price for each condition ............

 

In theory if each ASIN (GetLowestOfferListingsForASINResult) has at least 1 'Good' offer then during import I should also have 15 different values for the variable MIN_Condition_Good as it goes through the GetLowestOfferListingsForASINResult(s).

 

Example :

15 responses with roughly 10 offers each (122 actual total OfferListings though)

EACH OfferListing will have the lowest of each grade for each group (GetLowestOfferListingsForASINResult by ASIN) imported

 

 

Now, here's is a list of the 122 offer listings, grouped by ASIN, with each group sorted by condition, then by price:

<response>
  <result asin="B00B9ZH4UY">
    <listing condition="Acceptable" price="1.61"/>
    <listing condition="Acceptable" price="1.84"/>
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="0.01"/>
    <listing condition="Mint" price="1.28"/>
    <listing condition="Mint" price="1.87"/>
    <listing condition="Mint" price="5.09"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="1.61"/>
    <listing condition="VeryGood" price="1.86"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00B9ZHWK6">
    <listing condition="Acceptable" price="1.61"/>
    <listing condition="Acceptable" price="1.85"/>
    <listing condition="Good" price="1.59"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="1.78"/>
    <listing condition="Mint" price="2.48"/>
    <listing condition="VeryGood" price="1.76"/>
    <listing condition="VeryGood" price="1.78"/>
    <listing condition="VeryGood" price="1.87"/>
    <listing condition="VeryGood" price="1.94"/>
  </result>
  <result asin="B00B9ZIIUY">
    <listing condition="Good" price="1.96"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Good" price="3.99"/>
    <listing condition="Mint" price="2.48"/>
    <listing condition="Mint" price="5.70"/>
    <listing condition="VeryGood" price="2.10"/>
    <listing condition="VeryGood" price="5.58"/>
    <listing condition="VeryGood" price="5.59"/>
    <listing condition="VeryGood" price="9.25"/>
  </result>
  <result asin="B00B9ZJ4CU">
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="1.75"/>
    <listing condition="Mint" price="1.77"/>
    <listing condition="Mint" price="5.87"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00B9ZJ9U2">
    <listing condition="Acceptable" price="1.84"/>
    <listing condition="Good" price="1.82"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="1.87"/>
    <listing condition="Mint" price="1.87"/>
    <listing condition="Mint" price="2.67"/>
    <listing condition="Mint" price="7.13"/>
    <listing condition="VeryGood" price="1.85"/>
    <listing condition="VeryGood" price="2.10"/>
    <listing condition="VeryGood" price="6.98"/>
  </result>
  <result asin="B00B9ZKETC">
    <listing condition="Acceptable" price="0.67"/>
    <listing condition="Acceptable" price="1.66"/>
    <listing condition="Good" price="1.64"/>
    <listing condition="Good" price="1.66"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="1.72"/>
    <listing condition="Mint" price="2.48"/>
    <listing condition="VeryGood" price="1.70"/>
    <listing condition="VeryGood" price="1.72"/>
    <listing condition="VeryGood" price="1.98"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00B9ZM2J2">
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="0.01"/>
    <listing condition="Mint" price="0.03"/>
    <listing condition="Mint" price="2.03"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00B9ZMZY4">
    <listing condition="Acceptable" price="1.61"/>
    <listing condition="Good" price="0.96"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="0.98"/>
    <listing condition="Mint" price="1.00"/>
    <listing condition="Mint" price="2.03"/>
    <listing condition="VeryGood" price="0.98"/>
    <listing condition="VeryGood" price="1.61"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00CC7JHQ2">
    <listing condition="Good" price="1.91"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="3.69"/>
    <listing condition="Mint" price="3.71"/>
    <listing condition="Mint" price="5.87"/>
    <listing condition="VeryGood" price="2.08"/>
    <listing condition="VeryGood" price="2.10"/>
    <listing condition="VeryGood" price="5.75"/>
  </result>
  <result asin="B00D1GG950">
    <listing condition="Good" price="1.96"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="4.85"/>
    <listing condition="Mint" price="4.87"/>
    <listing condition="VeryGood" price="2.08"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>
  <result asin="B00D9TETII">
    <listing condition="Good" price="2.21"/>
    <listing condition="Good" price="2.23"/>
    <listing condition="Good" price="3.92"/>
    <listing condition="Mint" price="11.82"/>
    <listing condition="Mint" price="11.84"/>
    <listing condition="Mint" price="12.24"/>
    <listing condition="VeryGood" price="2.23"/>
    <listing condition="VeryGood" price="2.23"/>
    <listing condition="VeryGood" price="4.01"/>
  </result>
  <result asin="B00D9TT3V6">
    <listing condition="Good" price="6.27"/>
    <listing condition="Good" price="6.47"/>
    <listing condition="Mint" price="7.85"/>
    <listing condition="VeryGood" price="6.59"/>
    <listing condition="VeryGood" price="30.61"/>
  </result>
  <result asin="B00EBFKQB8">
    <listing condition="Good" price="2.45"/>
    <listing condition="Mint" price="2.49"/>
    <listing condition="Mint" price="33.00"/>
    <listing condition="VeryGood" price="2.47"/>
  </result>
  <result asin="B00F6IIIZK">
    <listing condition="Good" price="6.60"/>
    <listing condition="Good" price="10.25"/>
    <listing condition="Mint" price="9.00"/>
    <listing condition="Mint" price="9.02"/>
    <listing condition="Mint" price="10.72"/>
    <listing condition="VeryGood" price="6.62"/>
    <listing condition="VeryGood" price="6.62"/>
    <listing condition="VeryGood" price="10.40"/>
    <listing condition="VeryGood" price="12.23"/>
  </result>
  <result asin="B00FY5B3M"/>
</response>

Removing all listings except those where condition = "Good" leaves us with:

<response>
  <result asin="B00B9ZH4UY">
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZHWK6">
    <listing condition="Good" price="1.59"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZIIUY">
    <listing condition="Good" price="1.96"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Good" price="3.99"/>
  </result>
  <result asin="B00B9ZJ4CU">
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZJ9U2">
    <listing condition="Good" price="1.82"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZKETC">
    <listing condition="Good" price="1.64"/>
    <listing condition="Good" price="1.66"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZM2J2">
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00B9ZMZY4">
    <listing condition="Good" price="0.96"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00CC7JHQ2">
    <listing condition="Good" price="1.91"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00D1GG950">
    <listing condition="Good" price="1.96"/>
    <listing condition="Good" price="2.03"/>
  </result>
  <result asin="B00D9TETII">
    <listing condition="Good" price="2.21"/>
    <listing condition="Good" price="2.23"/>
    <listing condition="Good" price="3.92"/>
  </result>
  <result asin="B00D9TT3V6">
    <listing condition="Good" price="6.27"/>
    <listing condition="Good" price="6.47"/>
  </result>
  <result asin="B00EBFKQB8">
    <listing condition="Good" price="2.45"/>
  </result>
  <result asin="B00F6IIIZK">
    <listing condition="Good" price="6.60"/>
    <listing condition="Good" price="10.25"/>
  </result>
  <result asin="B00FY5B3M"/>
</response>

And after removing all prices except the first (lowest) one in each group we'll have:

<response>
  <result asin="B00B9ZH4UY">
    <listing condition="Good" price="0.01"/>
  </result>
  <result asin="B00B9ZHWK6">
    <listing condition="Good" price="1.59"/>
  </result>
  <result asin="B00B9ZIIUY">
    <listing condition="Good" price="1.96"/>
  </result>
  <result asin="B00B9ZJ4CU">
    <listing condition="Good" price="0.01"/>
  </result>
  <result asin="B00B9ZJ9U2">
    <listing condition="Good" price="1.82"/>
  </result>
  <result asin="B00B9ZKETC">
    <listing condition="Good" price="1.64"/>
   </result>
  <result asin="B00B9ZM2J2">
    <listing condition="Good" price="0.01"/>
  </result>
  <result asin="B00B9ZMZY4">
    <listing condition="Good" price="0.96"/>
   </result>
  <result asin="B00CC7JHQ2">
    <listing condition="Good" price="1.91"/>
  </result>
  <result asin="B00D1GG950">
    <listing condition="Good" price="1.96"/>
  </result>
  <result asin="B00D9TETII">
    <listing condition="Good" price="2.21"/>
  </result>
  <result asin="B00D9TT3V6">
    <listing condition="Good" price="6.27"/>
  </result>
  <result asin="B00EBFKQB8">
    <listing condition="Good" price="2.45"/>
  </result>
  <result asin="B00F6IIIZK">
    <listing condition="Good" price="6.60"/>
  </result>
  <result asin="B00FY5B3M"/>
</response>

That is 15 offer listings, each of them being the lowest (by price) in the "Good" category in each ASIN group. Note that the last group is empty, because it does not have any offer listings in the "Good" category.

 

Now, please compare these 15 listings with the 16 records imported by my stylesheet:

ASIN,MIN_Condition_Good
"B00B9ZH4UY","0.01"
"B00B9ZHWK6","1.59"
"B00B9ZIIUY","1.96"
"B00B9ZJ4CU","0.01"
"B00B9ZJ9U2","1.82"
"B00B9ZKETC","1.64"
"B00B9ZM2J2","0.01"
"B00B9ZMZY4","0.96"
"B00CC7JHQ2","1.91"
"B00D1GG950","1.96"
"B00D9TETII","2.21"
"B00D9TT3V6","6.27"
"B00EBFKQB8","2.45"
"B00F6IIIZK","6.60"
"B00FY5B3M",""

and tell me how this is different from what you said.

Link to comment
Share on other sites

The easiest way to explain ............. I already have a complex file based on every OfferListing. I do not want to rewrite it.

 

I want all OfferListings imported per ASIN and not just 1 per condition.

 

Let's look at a single ASIN :

<result asin="B00B9ZH4UY">
    <listing condition="Acceptable" price="1.61"/>
    <listing condition="Acceptable" price="1.84"/>
    <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="0.01"/>
    <listing condition="Mint" price="1.28"/>
    <listing condition="Mint" price="1.87"/>
    <listing condition="Mint" price="5.09"/>
    <listing condition="VeryGood" price="0.01"/>
    <listing condition="VeryGood" price="1.61"/>
    <listing condition="VeryGood" price="1.86"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>

Notice the big jump from the 0.01 to the next lowest per condition ?

 

Granted on this one there are 3 OfferListings in 3 conditions at that price point. So maybe it IS only worth 0.01

 

BUT ....  the other day (and this is quite common) there was someone who priced a miss graded copy very low.

 

Let's say we had this instead:

<result asin="B00B9ZH4UY">
    <listing condition="Acceptable" price="1.01"/>
    <listing condition="Acceptable" price="1.84"/>
//  <listing condition="Good" price="0.01"/>
    <listing condition="Good" price="1.61"/>
    <listing condition="Good" price="2.03"/>
    <listing condition="Mint" price="1,01"/>
    <listing condition="Mint" price="1.28"/>
    <listing condition="Mint" price="1.87"/>
    <listing condition="Mint" price="5.09"/>
    <listing condition="VeryGood" price="1.01"/>
    <listing condition="VeryGood" price="1.61"/>
    <listing condition="VeryGood" price="1.86"/>
    <listing condition="VeryGood" price="2.10"/>
  </result>

Without having the second Good to see that the 0.01 was an anomaly I would never know.

 

ANYWAY ..... apparently what I want isn't possible (unless someone has an idea ... but if you didn't then I doubt it) so I'll just write a calc. using GetNthRecord which I did before .

 

I appreciate the help and the time you've taken to write all that out.

 

If I find a solution I'll post back and will check in case someone posts anything ......

 

Link to comment
Share on other sites

I want all OfferListings imported per ASIN and not just 1 per condition.

 

Well, this is post #18 in this thread and it's the first time you said so...

 

The other thing is that it's quite jarring to be told at this point "thank you, that's not what I need", without any explanation (until coaxed).

 

 

apparently what I want isn't possible

 

FYI, XSLT is a Turing-complete language - which in simple words means that ANY manipulation of data is possible. So this is merely a question of skills. However, I'd like to be to be sure I fully understand the requirements before I invest any more time and effort into this. So is it correct you want to import (in this example) 122 records, with each record having (among others) these fields:

<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Acceptable" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Good" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_VeryGood" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_LikeNew" TYPE="TEXT"/>

where the "minimum" refers to records within the same ASIN group?

 

I don't see why this would be difficult, but - again - I am puzzled why you would want to do this, since it unnecessarily replicates the same data by a factor of ~10 and provides at best a limited functionality.

 

Wouldn't it be better to construct a self-join relationship in Filemaker, based on matching ASIN and Condition? That way you could easily compare each price with the minimum and/or maximum and/or average in its group, conditionally format the lowest price and a million other things - without being limited to the hard-coded imported stats.

               

Link to comment
Share on other sites

I thought that my current posted stylesheet shows I'm importing every OfferListing ... but maybe that's just me and I guess it's not stated well enough until around #12.

 

Post # 12

 

Having them all on each OfferListing is ......

 

I'm playing with this but not getting any results.

 

Maybe my explanation isn't up to par.

 

Example :

15 responses with roughly 10 offers each (122 actual total OfferListings though)

EACH OfferListing will have the lowest of each grade for each group (GetLowestOfferListingsForASINResult by ASIN) imported just as it does currently for the MIN_Landed/MAX_Landed and MIN_Listing/MAX_Listing

 

Anyway .......

 

 

So is it correct you want to import (in this example) 122 records, with each record having (among others) these fields:

<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Acceptable" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_Good" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_VeryGood" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="MIN_Condition_LikeNew" TYPE="TEXT"/>

where the "minimum" refers to records within the same ASIN group?

 

That is correct ...

 

EDIT :

 

Also ... I thought (apparently wrong though) that my 3rd comment in post #1 explained things :

 

I'm importing multiple offer listings from Amazon and have a working stylesheet. I'm trying to set several variables for each record

 

My apologies for the confusion but I thought I had explained it between this and the stylesheet ....

Edited by Cabinetman
Link to comment
Share on other sites

Well, there have been numerous stylesheets posted. Also, one tends to focus more on what's needed rather than get bogged down trying to decipher code that doesn't work.

 

And, if you really want to know, what threw me the most was the fact that you are importing the same data 10 times. I mean, I never considered the possibility you would want to import the lowest offering as an individual record (along with all other offerings) as well as an attribute of all the other records. It did not even cross my mind, until you said so explicitly.

 

Anyway, have you thought about the relationship alternative?

Link to comment
Share on other sites

 

Anyway, have you thought about the relationship alternative?

 

Yes ... I already incorporate it in part.

 

I don't understand why you seem so against my inclusion of extra data within each record. But I can appreciate it non the less.

 

All I want to do is include these extra variables during import by editing my current stylesheet.

Link to comment
Share on other sites

I don't understand why you seem so against my inclusion of extra data within each record.

 

Because we train ourselves to remove all redundancy. That's the very basis of all relational databases. And it's not just about performance. Things are much easier to do when data is properly structured - partly (perhaps mostly) because the database tools are built under the assumption that the data contained in them will be normalized.

 

Just as an example: consider how much work it would take to add an average price to the display, using your method. My method would require nothing more than one additional summary field.

Link to comment
Share on other sites

 

Just as an example: consider how much work it would take to add an average price to the display, using your method. My method would require nothing more than one additional summary field.

Yet if I have only 1 offer for 'Good' for that ASIN I CAN'T do a summary ....... and decide to price slightly higher than the lowest.'Good'.

 

If instead I have all 3 then I can .......

 

Or am I missing something ?

Link to comment
Share on other sites

Yet if I have only 1 offer for 'Good' for that ASIN I CAN'T do a summary

 

Why not? If the summary field summarizes over a (self-join) relationship, and the self-join relationship is based on matching ASIN and Condition, then the related set includes the currently viewed record, and the summary field will "summarize" only it, if necessary.

Link to comment
Share on other sites

BTW, just as an exercise, consider the following stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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="/">

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

<METADATA>
    <FIELD NAME="ASIN" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="Condition" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="Price" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="MIN_Condition_Good" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
</METADATA>

<RESULTSET FOUND="">

<xsl:for-each select="amz:GetLowestOfferListingsForASINResponse/amz:GetLowestOfferListingsForASINResult">

<xsl:variable name="MIN_Condition_Good">
    <xsl:for-each select="amz:Product/amz:LowestOfferListings/amz:LowestOfferListing[amz:Qualifiers/amz:ItemSubcondition='Good']">
        <xsl:sort select="amz:Price/amz:ListingPrice/amz:Amount" data-type="number" order="ascending"/>
         <xsl:if test="position()=1">
            <xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/>
        </xsl:if>   
    </xsl:for-each>
</xsl:variable>   

<xsl:for-each select="amz:Product/amz:LowestOfferListings/amz:LowestOfferListing">
<ROW MODID="{position()}" RECORDID="">
    <COL><DATA><xsl:value-of select="../../../@ASIN"/></DATA></COL>
    <COL><DATA><xsl:value-of select="amz:Qualifiers/amz:ItemSubcondition"/></DATA></COL>
    <COL><DATA><xsl:value-of select="amz:Price/amz:ListingPrice/amz:Amount"/></DATA></COL>
    <COL><DATA><xsl:value-of select="$MIN_Condition_Good"/></DATA></COL>
</ROW>
</xsl:for-each>

</xsl:for-each>
</RESULTSET>
</FMPXMLRESULT>

</xsl:template>
</xsl:stylesheet>

However, I sincerely recommend not going that way.

Link to comment
Share on other sites

First I was mistakenly referring to the 'only import the 4 condition prices instead of all the offerlistings' .... sorry.

 

I'm going with a mixture of both .... but sticking primarily to my previous use of (and your recommendation of) the relationship.

 

Thanks again.

Link to comment
Share on other sites

  • 4 weeks later...

 

<xsl:variable name="MIN_Condition_Good">

     <xsl:for-each select="..//amz:Qualifiers/amz:ItemSubcondition">

        <xsl:sort data-type="text" order="descending"/>

        <xsl:if test="starts-with(.,'Good')">

            <xsl:value-of select="../..//amz:Price/amz:ListingPrice/amz:Amount[1]"/>

NOTE: the "//" means ALL, so that's what you get?

 

just the [1] should do it. you can also revise the select, so you get the first correct "Good" without the for-each looping, but I don't really have the time to sort through all this post (confused, am I!)

Link to comment
Share on other sites

This topic is 3625 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.