将复杂的XML数据导入到多个FileMaker表中 [英] importing complex XML data into multiple FileMaker tables

查看:66
本文介绍了将复杂的XML数据导入到多个FileMaker表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解导入FileMaker(csv,xml)的基础知识,并且对XSLT有所了解.

I understand the basics of import to FileMaker (csv, xml) and I know a little about XSLT.

我有一个数据集,其中包含需要导入FileMaker的列表.为此有3个表-主表,数据点表和位置表.我的数据如下:

I have a data set containing lists that I need to import into FileMaker. There are 3 tables for this - the main table, the datapoints table and the positions table. My data looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<result>

<data mode="test" ram="on">
    33,869
    34,115
    46,074
    225,233, E
    226,122, E
    235,763, E
    237,408, E
    237,722, E
    242,503
    256,271
    273,741
</data>

<statistics>

    <positions>
        <position id="1" unit="c">0,00</position>
        <position id="2" unit="c">5,05</position>
        <position id="3" unit="c">14,30</position>
        <position id="4" unit="c">23,47</position>
    </positions>
</statistics>    
</result>

如何一次性将该XML导入FM?我知道我需要将其转换为fmpxmlresult,但是我阅读的所有内容都假设XML本质上是精美的CSV-没有相关/子行的单独行.

how do I import this XML into FM in one go? I understand I need to convert it to fmpxmlresult, but everything I've read assumes that the XML is essentially a fancy CSV - individual rows without related/sub-rows.

是的, positions 数据已正确进行XML修饰,而 data 数据则以换行符分隔,我知道这不是XML方式,而是这种方式我收到了数据.

And yes, the positions data is properly XML'ified, and the data data is newline-seperated and I know that's not the XML way, but it's the way I receive the data.

有什么我可以做的使我的用户容易的事情吗?如果绝对必要,我可以在FileMaker之外对数据进行预处理,但是如果可能的话,我希望避免这种情况.

Is there something I can do to make this easy for my users? I can pre-process the data outside of FileMaker if absolutely necessary, but would like to avoid that if possible.

(从此问题中分离出来-

(split off from this question - Export and Import date from/into current record only in FileMaker 18 - which contained a simplified version of this question and an unrelated other question, someone remarked I should ask one question at a time)

推荐答案

要将positions导入到具有PositionIDUnitValue字段的表中,可以使用以下样式表:

To import the positions into a table with fields for PositionID, Unit and Value, you can use the following stylesheet:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.filemaker.com/fmpxmlresult">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="/result">
    <FMPXMLRESULT>
        <METADATA>
            <FIELD NAME="PositionID"/>
            <FIELD NAME="Unit"/>
            <FIELD NAME="Value"/>
        </METADATA>
        <RESULTSET>
            <xsl:for-each select="statistics/positions/position">
                <ROW>
                    <COL>
                        <DATA>
                            <xsl:value-of select="@id"/>
                        </DATA>
                    </COL>
                    <COL>
                        <DATA>
                            <xsl:value-of select="@unit"/>
                        </DATA>
                    </COL>
                    <COL>
                        <DATA>
                            <xsl:value-of select="."/>
                        </DATA>
                    </COL>
                </ROW>
            </xsl:for-each>
        </RESULTSET>
    </FMPXMLRESULT>
</xsl:template>

</xsl:stylesheet>


要将data导入具有两个目标字段的表(不确定如何调用它们),可以使用:


To import the data into a table with two target fields (not sure what to call them), you can use:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.filemaker.com/fmpxmlresult">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="/result">
    <FMPXMLRESULT>
        <METADATA>
            <FIELD NAME="A"/>
            <FIELD NAME="B"/>
        </METADATA>
        <RESULTSET>
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="data"/>
            </xsl:call-template>
        </RESULTSET>
    </FMPXMLRESULT>
</xsl:template>

<xsl:template name="tokenize">
    <xsl:param name="text"/>
    <xsl:param name="delimiter" select="'&#10;'"/>
    <xsl:param name="sep" select="', '"/>
    <xsl:variable name="token" select="normalize-space(substring-before(concat($text, $delimiter), $delimiter))" />
    <xsl:if test="$token">
        <ROW>
            <COL>
                <DATA>
                    <xsl:value-of select="substring-before(concat($token, $sep), $sep)" />
                </DATA>
            </COL>
            <COL>
                <DATA>
                    <xsl:value-of select="substring-after($token, $sep)" />
                </DATA>
            </COL>
        </ROW>
    </xsl:if>
    <xsl:if test="contains($text, $delimiter)">
        <!-- recursive call -->
        <xsl:call-template name="tokenize">
            <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

这篇关于将复杂的XML数据导入到多个FileMaker表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆