2012-09-12 45 views
0

第一...本論壇幫助我多次找到問題的答案,而無需問自己的問題。謝謝你的回答。 我保證會在這個論壇協議之後做的更好。XSLT ..故障設置變量,包含多個響應的XML中的最小值

我不能完全肯定,我的問題是說不夠好,所以我就畫出來了一下.....

我得到的XML包含在響應中的結果「設置」每個人都需要對我的進口有自己的「最低限度」。

這裏是非常濃縮的樣子只是給你一個想法:

<?xml version="1.0"?> 
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> 
    <GetLowestOfferListingsForASINResult ASIN="0470067802" status="Success"></GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="0684177722" status="Success"></GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="0470052325" status="Success"></GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="0470182601" status="Success"></GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="0525950869" status="Success"></GetLowestOfferListingsForASINResult> 
</GetLowestOfferListingsForASINResponse> 

進一步其實有3次出現的每個結果中的「金額」元素的返回....

目前我變量在整個響應中採用每個「量」,而不是從每個結果集中獲取。

XLST:

<?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="/"> 
    <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> 
    <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="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="LandedPrice" TYPE="TEXT"/> 
       <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ListingPrice" TYPE="TEXT"/> 
       <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Shipping" 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: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: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> 
        </ROW> 
       </xsl:for-each> 
      </RESULTSET> 
     </FMPXMLRESULT> 
    </xsl:template> 
</xsl:stylesheet> 

下面是測試XML ....

<?xml version="1.0"?> 
<GetLowestOfferListingsForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> 
    <GetLowestOfferListingsForASINResult ASIN="0060784776" status="Success"> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> 
        <ASIN>0060784776</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.98</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Collectible</ItemCondition> 
         <ItemSubcondition>Mint</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.98</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>VeryGood</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.00</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.00</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Acceptable</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.44</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>5.45</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>New</ItemCondition> 
         <ItemSubcondition>New</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.45</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.45</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>VeryGood</ItemSubcondition> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.45</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>5.46</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>New</ItemCondition> 
         <ItemSubcondition>New</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.95</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>9.95</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
      </LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="0140171223" status="Success"> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> 
        <ASIN>0140171223</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>6.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.00</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Acceptable</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>6.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.00</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Mint</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>7.49</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.50</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Acceptable</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.48</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.49</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>New</ItemCondition> 
         <ItemSubcondition>New</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.49</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.50</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Mint</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.78</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.79</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.98</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>4.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>New</ItemCondition> 
         <ItemSubcondition>New</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>8.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>5.00</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
      </LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
    <GetLowestOfferListingsForASINResult ASIN="014100181X" status="Success"> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> 
        <ASIN>014100181X</ASIN> 
       </MarketplaceASIN> 
      </Identifiers> 
      <LowestOfferListings> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>VeryGood</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <Price> 
         <LandedPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </LandedPrice> 
         <ListingPrice> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>3.99</Amount> 
         </ListingPrice> 
         <Shipping> 
          <CurrencyCode>USD</CurrencyCode> 
          <Amount>0.00</Amount> 
         </Shipping> 
        </Price> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
         <FulfillmentChannel>Merchant</FulfillmentChannel> 
        </Qualifiers> 
        <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> 
       </LowestOfferListing> 
       <LowestOfferListing> 
        <Qualifiers> 
         <ItemCondition>Used</ItemCondition> 
         <ItemSubcondition>Good</ItemSubcondition> 
        </Qualifiers> 
        <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> 
       </LowestOfferListing> 
      </LowestOfferListings> 
     </Product> 
    </GetLowestOfferListingsForASINResult> 
</GetLowestOfferListingsForASINResponse> 

回答

1

如果我理解正確的話,你的問題是,你的代碼是目前發現的最低值Amount文件,而您卻希望找到每個amz:LowestOfferListing中的最低金額。

您將需要更改兩件事。

首先,您不需要將值設置爲$MIN_Landed一次,而是需要爲每個結果集綁定該變量一次。因此,將xsl:variable聲明移動到for-each中,每個結果集將被評估一次。其次,您想要的值是結果集中的最低值,而不是文檔中的最低值。因此,您需要更改表達式中的select屬性,以確定$MIN_Landed變量的值,以便它僅選擇在當前結果集內發生的amz:Amount元素。 (提示:用'.//'開始select表達式,而不是'//'。)