Universal XSLT

<?xml version="1.0" encoding="utf-8" ?>

<!-- The one-fits-all XSLT for FileMaker.

     Transforms arbitrary XML grammars and namespaces
          into FileMaker records. Every node or attribute one
	       record.

     Usage: Import your XML data with grammar FMPXMLRESULT using this file as
          XSLT stylesheet into a new FM table.

     Jens Teich v-0.4 12.08.2013
     -->


<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns="http://www.filemaker.com/fmpxmlresult">

  <xsl:template match="/">
    <FMPXMLRESULT>

      <ERRORCODE>0</ERRORCODE>
      <PRODUCT BUILD="" NAME="" VERSION=""/>
      <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

      <METADATA>
	<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="path" TYPE="TEXT"/>
	<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="parent" TYPE="TEXT"/>
	<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="node" TYPE="TEXT"/>
	<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="value" TYPE="TEXT"/>
	<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="type" TYPE="TEXT"/>
      </METADATA>

      <RESULTSET FOUND="">
      	<xsl:apply-templates />
      </RESULTSET>

    </FMPXMLRESULT>
  </xsl:template>

  <xsl:template match="node()"> <!-- Template handling all nodes -->
    <xsl:if test="self::*"> <!-- no text nodes -->
      <ROW MODID="" RECORDID="">
	<COL>
	  <DATA>
	    <xsl:for-each select="ancestor-or-self::*">
	      <xsl:value-of select="name()" /><xsl:text>/</xsl:text>
	    </xsl:for-each>
	  </DATA>
	</COL>
	<COL><DATA><xsl:value-of select="name(parent::*)"/></DATA></COL>
	<COL><DATA><xsl:value-of select="name()"/></DATA></COL>
	<COL><DATA>
	  <xsl:if test="not(*)">
	    <xsl:value-of select="."/>
	  </xsl:if>
	</DATA></COL>
	<COL><DATA><xsl:text>Node</xsl:text></DATA></COL>
      </ROW>
    </xsl:if>

    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates />
  </xsl:template>
  
  <xsl:template match="@*"> <!-- Template handling attribute nodes -->
    <ROW MODID="" RECORDID="">
      <COL>
	<DATA>
	  <xsl:for-each select="ancestor-or-self::*">
	    <xsl:value-of select="name()" /><xsl:text>/</xsl:text>
	  </xsl:for-each>
	</DATA>
      </COL>
      <COL><DATA><xsl:value-of select="name(parent::*)"/></DATA></COL>
      <COL><DATA><xsl:value-of select="name()"/></DATA></COL>
      <COL><DATA><xsl:value-of select="."/></DATA></COL>
      <COL><DATA><xsl:text>Attribute</xsl:text></DATA></COL>
    </ROW>
  </xsl:template>
  
</xsl:stylesheet>

Usage:

Create new empty FileMaker file. Any current version of FileMaker will do (fp7 or fmp12, even fp5 should work).

Put your XML source file (I will call it data.xml here) and the file above into the same folder as your new FileMaker file.

Select file / import records / xml.

For the data source select ‚file‘ and and enter ‚file:data.xml‘.

Check the box to use a stylesheet and again select ‚file‘. Enter ‚file:universal-import.xslt‘.

Click ‚continue …‘.

Now select creation of a new table in upper right corner of window. Then start importing.

Result is a new table in FileMaker with four fields. It will create a record for every node and every attribute, containing every name and value. This is probably more than you want. But now your are inside FileMaker with the XML data. And it needs no XSLT programming skills at all!

Even easier it is with this drag-and-drop solution by Thomas Giesinger (many thanks)!

If you need a more special XSLT just ask via mail.

Author: Jens Teich (info[at]jensteich[dot]de).