gpt4 book ai didi

xml - filemaker xml 通过 xslt 导出

转载 作者:数据小太阳 更新时间:2023-10-29 02:14:06 25 4
gpt4 key购买 nike

我正在尝试从我们的 Filemaker 数据库导出一些数据并通过 XSLT 转换它

我已经掌握了大部分方法,但在一些嵌套数据上卡住了:

XML 输出的当前结构是:

    <?xml version="1.0" encoding="UTF-8"?>
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="07-18-2011" NAME="FileMaker" VERSION="ProAdvanced 11.0v4"/>
<DATABASE DATEFORMAT="D/m/yyyy" LAYOUT="" NAME="bubbles.fp7" RECORDS="34604" TIMEFORMAT="k:mm:ss "/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="description intro" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Description Line 1" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Description Line 2" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="description short" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="description W3" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Destination URL" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="EAN Code" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="product code W1" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="product group name" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="product name W6" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="stock_for_sale_quantity" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="UPC Code" TYPE="NUMBER"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="web link standard" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="products_ADDITIONAL_IMAGES::full url" TYPE="TEXT"/>
</METADATA>
<RESULTSET FOUND="6">
<ROW MODID="5678" RECORDID="5051">
<COL>
<DATA>description info here</DATA>
</COL>
<COL>
<DATA> desc line 1</DATA>
</COL>
<COL>
<DATA>desc line 2</DATA>
</COL>
<COL>
<DATA>short description here</DATA>
</COL>
<COL>
<DATA>
Reall long description goes in here</DATA>
</COL>
<COL>
<DATA>url to product</DATA>
</COL>
<COL>
<DATA/>
</COL>
<COL>
<DATA>SKU</DATA>
</COL>
<COL>
<DATA>Acoustic guitars</DATA>
</COL>
<COL>
<DATA>Epiphone EJ-200 Acoustic Guitar Vintage Sunburst EJ200</DATA>
</COL>
<COL>
<DATA>0</DATA>
</COL>
<COL>
<DATA>711106264509</DATA>
</COL>
<COL>
<DATA>http://www.mywebsite.co.uk/catalog/product/view/id/15186</DATA>
</COL>
<COL>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_01.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_02.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_03.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_04.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_05.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/additional/epiej200vsbrst_06.jpg</DATA>
<DATA>http://www.mywebsite.co.uk/store/images/uploads/epiej200vsbrst.jpg</DATA>
</COL>
</ROW>

我的 XSL 在一定程度上可以正常工作,但我不能完全用它来挑选出每张图片:

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0" exclude-result-prefixes="fmp">
<xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes"/>
<xsl:template match="/">
<product>
<product_count>
<xsl:value-of select="count(//fmp:ROW)"/>
</product_count>
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<product_info>
<description_info>
<xsl:value-of select="fmp:COL[1]/fmp:DATA"/>
</description_info>
<desc_line_1>
<xsl:value-of select="fmp:COL[2]/fmp:DATA"/>
</desc_line_1>
<desc_line_2>
<xsl:value-of select="fmp:COL[3]/fmp:DATA"/>
</desc_line_2>
<short_description>
<xsl:value-of select="fmp:COL[4]/fmp:DATA"/>
</short_description>
<long_description>
<xsl:value-of select="fmp:COL[5]/fmp:DATA"/>
</long_description>
<dest_url>
<xsl:value-of select="fmp:COL[6]/fmp:DATA"/>
</dest_url>
<ean>
<xsl:value-of select="fmp:COL[7]/fmp:DATA"/>
</ean>
<sku>
<xsl:value-of select="fmp:COL[8]/fmp:DATA"/>
</sku>
<group_name>
<xsl:value-of select="fmp:COL[9]/fmp:DATA"/>
</group_name>
<product_name>
<xsl:value-of select="fmp:COL[10]/fmp:DATA"/>
</product_name>
<stock_level>
<xsl:value-of select="fmp:COL[11]/fmp:DATA"/>
</stock_level>
<upc>
<xsl:value-of select="fmp:COL[12]/fmp:DATA"/>
</upc>
<web_link>
<xsl:value-of select="fmp:COL[13]/fmp:DATA"/>
</web_link>
<position>
<xsl:value-of select="fmp:DATA"/>
</position>
<images>
<xsl:variable name="count" select="count(fmp:COL[14]/fmp:DATA)"/>
<image_count>
<xsl:value-of select="$count"/>
</image_count>
<xsl:for-each select="fmp:COL[14]/fmp:DATA[position()&lt;=$count]">
<img>
<xsl:value-of select="position()"/>
</img>
</xsl:for-each>
</images>
</product_info>
</xsl:for-each>
</product>
</xsl:template>

除了给我正确数量的标签但没有数据的位之外,这有效

    <images>
<image_count>7</image_count>
<img/>
<img/>
<img/>
<img/>
<img/>
<img/>
<img/>
</images>

有人可以帮助完成最后一个小循环吗?

最佳答案

你让事情变得比你需要的复杂得多:

<xsl:for-each select="fmp:COL[14]/fmp:DATA">
<img>
<xsl:value-of select="."/>
</img>
</xsl:for-each>

给你

<img>http://www.absolutemusic.co.uk/store/images/uploads/additional/epiej200vsbrst_01.jpg</img>
<img>http://www.absolutemusic.co.uk/store/images/uploads/additional/epiej200vsbrst_02.jpg</img>
....

顺便说一句,我过去不得不编写 filemaker XSLT 并让自己保持清醒(并且不必记住每个字段的正确列索引)我使用了这样的技巧:

<xsl:variable name="mdf" select="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD" />
<xsl:variable name="descIntro" select="count($mdf[
following-sibling::fmp:FIELD/@NAME = 'description intro']) + 1" />
<xsl:variable name="descL1" select="count($mdf[
following-sibling::fmp:FIELD/@NAME = 'Description Line 1']) + 1" />

等等。这会为每个字段名称创建一个变量,其中包含该字段的正确索引,因此您可以使用 fmp:COL[$images] 之类的表达式,而不是 fmp:COL[14]。这还有一个额外的好处,即如果您稍后更改导出定义以包含 XSLT 自动补偿的其他字段,则您不必手动修改所有数字。

关于xml - filemaker xml 通过 xslt 导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13137517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com