1

我已经搜索了几个小时,但没有找到一个允许第一个位置最低的示例。我得到'False'而不是返回的值......

示例 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>

无法正常工作的示例 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>

请帮忙!

我真的不想发布这么多亚马逊代码,但在这里它被简化为一个简单的响应

显然顺序很重要......

可以工作的示例 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="$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>
4

1 回答 1

0

展示你实际使用的代码,或者至少是一个呈现所有可能因素的传真,比如命名空间,这是值得的。交换这个:

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

如果这不能解决问题,则您的 xsl 外部存在问题。这不利于您提供的来源。


档案

您的示例未显示您的代码在 XSL 中的位置,也不清楚源文档中的每个 Amount 是否始终位于 a、b、c、d、e、f、Price 元素中的每个元素之下,或者是否存在是一个根元素,如果是,那是什么。您的代码也不会关闭变量标记,也不会显示变量的输出方式。

假设上述任何一项都没有问题,您的“订单”属性应该是升序的,因为使用position() = '1',您正在寻找排序后位于顶部位置的节点。升序将最低值放在首位。

无论源文档结构如何,以下代码本身都会输出源文档中的最小值:

<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>
    <xsl:value-of select = "$MIN_Landed" />
</xsl:template>
于 2012-09-07T20:15:33.007 回答