importing complex XML data into multiple FileMaker tables

后端 未结 3 629
感动是毒
感动是毒 2021-01-26 10:13

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

I have a data set containing lists that I need to import into FileMaker. There

相关标签:
3条回答
  • 2021-01-26 10:31

    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>
    

    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>
    
    0 讨论(0)
  • 2021-01-26 10:40

    The import procedure is still as I described in my answer on the question you link to. You need an XSLT file to specify during import to transform your XML to FileMaker's schema. This is not very difficult with a simple source file, but still necessary.

    0 讨论(0)
  • 2021-01-26 10:45

    Here's how you can simplify the triple-import for the users:

    • create a global container
    • place it on the layout (or on a temp layout specifically for this process)
    • in your script use the Insert File script step to let the user choose a file
    • set it up to always insert a reference, no zipping, no choice
    • then you can GetAsText the container and extract the path into a variable $filePath
    • after that you can use the variable $filePath to specify the file in the proceeding imports and set them to run with no dialog.

    Voila!

    I don’t know why this answer has been voted down. It is a suggestion how to solve the Corresponding problem of choosing a source file once but performing two imports, as the poster asked in his reaction to the solution above.

    0 讨论(0)
提交回复
热议问题