使用filemaker重新排列XSLT元素

时间:2013-10-09 15:42:48

标签: xml magento xslt filemaker

我从Filemaker 12导出数据以构建SOAP调用以更新我们的网站(magento)

我可以得到几乎所有工作,除了我需要移动一些节点

我目前有(摘录)

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
  <RESULTSET FOUND="1">
    <ROW MODID="4431" RECORDID="31">
      <!-- column 15 -->
      <COL> <!-- customer group -->
        <DATA>all</DATA>
        <DATA>all</DATA>
        <DATA>education</DATA>
      </COL>
      <!-- column 16 -->
      <COL> <!-- qty -->
        <DATA>5</DATA>
        <DATA>10</DATA>
        <DATA>100</DATA>
      </COL>
      <!-- column 17 -->
      <COL> <!-- sale price -->
        <DATA>1300</DATA>
        <DATA>1250</DATA>
        <DATA>1225</DATA>
      </COL>
      <!-- column 18 -->
      <COL> <!-- website -->
        <DATA>1</DATA>
        <DATA>1</DATA>
        <DATA>2</DATA>
      </COL>
    </ROW>
  </RESULTSET>
</FMPXMLRESULT>

我希望它看起来像是:

<item>
    <customer_group>all</customer_group
    <qty>5</qty>
    <price>1300</price>
    <website>1</website>
</item>
<item>
    <customer_group>all</customer_group
    <qty>10</qty>
    <price>1250</price>
    <website>1</website>
</item>
<item>
    <customer_group>education</customer_group
    <qty>100</qty>
    <price>1225</price>
    <website>2</website>
</item>

我当前的样式表看起来像这样(再次只是相关的代码段)

                <xsl:for-each select="fmp:COL[15]/fmp:DATA">
                  <xsl:variable name="location">
                    <xsl:value-of select="position()" />
                  </xsl:variable>
                  <item>
                    <customer_group_id xsi:type="xsd:string">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[15]/fmp:DATA[$location]" />
                    </customer_group_id>
                    <qty xsi:type="xsd:int">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[16]/fmp:DATA[$location]" />
                    </qty>
                    <price xsi:type="xsd:double">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[17]/fmp:DATA[$location]" />
                    </price>
                    <website xsi:type="xsd:string">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[18]/fmp:DATA[$location]" />
                    </website>
                  </item>
                </xsl:for-each>

这几乎可以起作用,它将构建3个元素,包括所有customer_group,qty,price和website,但是,它不会带来任何数据。

有人可以帮忙吗?

整个filemaker输出在这里:                 0                                                                                                                                                                                                                                                                                                                                2bxdrumit5mk2                                   201             5511             516                                   2             1                                   鼓机                                   这里描述                                   简短的介绍                                   123.45                                   1                                   我-URL到产品                                   4                                   1700                                   2199年1月1日                                   2199年2月1日                                   2                                   所有             所有             教育                                   五             10             100                                   1300             1250             1225                                   1             1             2                                   鼓套件的东西                                                                      更多文字                                   0                                   stock_message                                   根据要求订购                                   1                                                                                                                                         

整个XSLT样式表在这里:

<?xml version="1.0" encoding="utf-8" standalone='no'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp" xmlns:sc="http://schemas.google.com/structuredcontent/2009" xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:gd="http://schemas.google.com/g/2005" xmlns:scp="http://schemas.google.com/structuredcontent/2009/products">
  <xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes" />
  <xsl:template match="/">
    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="urn:Magento">
      <SOAP-ENV:Body>
        <ns1:catalogProductUpdate>
          <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
            <sessionId xsi:type="xsd:string">sessionIDstring</sessionId>
            <product xsi:type="xsd:string">
              <xsl:value-of select="fmp:COL[1]/fmp:DATA" />
            </product>
            <productData>
              <categories SOAP-ENC:arrayType="ns:ArrayOfString[1]">
                <xsl:for-each select="fmp:COL[2]/fmp:DATA">
                  <item xsi:type="xsd:string">
                    <xsl:value-of select="." />
                  </item>
                </xsl:for-each>
              </categories>
              <websites SOAP-ENC:arrayType="ns:ArrayOfString[1]">
                <xsl:for-each select="fmp:COL[3]/fmp:DATA">
                  <item xsi:type="xsd:string">
                    <xsl:value-of select="." />
                  </item>
                </xsl:for-each>
              </websites>
              <name xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[4]/fmp:DATA" />
              </name>
              <description xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[5]/fmp:DATA" />
              </description>
              <short_description xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[6]/fmp:DATA" />
              </short_description>
              <weight xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[7]/fmp:DATA" />
              </weight>
              <status xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[8]/fmp:DATA" />
              </status>
              <url_key xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[9]/fmp:DATA" />
              </url_key>
              <visibility xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[10]/fmp:DATA" />
              </visibility>
              <category_ids />
              <website_ids />
              <price xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[11]/fmp:DATA" />
              </price>
              <special_from_date xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[12]/fmp:DATA" />
              </special_from_date>
              <special_to_date xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[13]/fmp:DATA" />
              </special_to_date>
              <tax_class_id xsi:type="xsd:string">
                <xsl:value-of select="fmp:COL[14]/fmp:DATA" />
              </tax_class_id>
              <tier_price SOAP-ENC:arrayType="ns:catalogProductTierPriceEntityArray[1]">
                <item_count>
                  <xsl:value-of select="count(//fmp:ROW/fmp:COL[15]/fmp:DATA)" />
                </item_count>
                <xsl:variable name="tierCount">
                  <xsl:value-of select="count(//fmp:ROW/fmp:COL[15]/fmp:DATA)" />
                </xsl:variable>
                <!-- count how many tiered thingys we have and hope that the data is correct in FM and there are no blank fields -->
                <item_var>
                  <xsl:value-of select="$tierCount" />
                </item_var>
                <xsl:variable name="count">
                  <xsl:number />
                </xsl:variable>
                <xsl:for-each select="fmp:COL[15]/fmp:DATA">
                  <xsl:variable name="location">
                    <xsl:value-of select="position()" />
                  </xsl:variable>
                  <item>
                    <customer_group_id xsi:type="xsd:string">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[15]/fmp:DATA[$location]" />
                    </customer_group_id>
                    <qty xsi:type="xsd:int">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[16]/fmp:DATA[$location]" />
                    </qty>
                    <price xsi:type="xsd:double">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[17]/fmp:DATA[$location]" />
                    </price>
                    <website xsi:type="xsd:string">
                      <xsl:value-of select="//fmp:ROW/fmp:COL[18]/fmp:DATA[$location]" />
                    </website>
                  </item>
                </xsl:for-each>
              </tier_price>
            </productData>
          </xsl:for-each>
        </ns1:catalogProductUpdate>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
  </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:0)

我设法通过以下方式解决了这个问题:

          <tier_price SOAP-ENC:arrayType="ns:catalogProductTierPriceEntityArray[1]">
            <xsl:for-each select="//fmp:ROW/fmp:COL[15]/fmp:DATA">
              <xsl:variable name="location" select="position()" />
              <item>
                <customer_group_id xsi:type="xsd:string">
                  <xsl:value-of select="//fmp:ROW/fmp:COL[15]/fmp:DATA[$location]" />
                </customer_group_id>
                <qty xsi:type="xsd:int">
                  <xsl:value-of select="//fmp:ROW/fmp:COL[16]/fmp:DATA[$location]" />
                </qty>
                <price xsi:type="xsd:double">
                  <xsl:value-of select="//fmp:ROW/fmp:COL[17]/fmp:DATA[$location]" />
                </price>
                <website xsi:type="xsd:string">
                  <xsl:value-of select="//fmp:ROW/fmp:COL[18]/fmp:DATA[$location]" />
                </website>
              </item>
            </xsl:for-each>
          </tier_price>