Universal XSLT für den Import beliebiger XML Daten

<?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>

7 thoughts on “Universal XSLT für den Import beliebiger XML Daten

  1. Eric

    Hallo !

    Wie genial ist das denn ? Diese XSLT Datei hätte Filemaker seit Jahren mit liefern müssen, um einen XML Import beliebiger Dateien möglich zu machen. Alle Dateien die ich getestet habe, haben auf Anhieb funktioniert.

    Vielen Dank !

    Eric

    Reply
  2. Binu Alexander

    I am not able to import this xml document .. some parent fields are returining empty e.g parent = verse = empty in filemaker after import

    The Gospel According to St. Matthew

    The book of the genealogy of Jesus Christ, the son of David, the son of Abraham.
    Abraham was the father of Isaac, and Isaac the father of Jacob, and Jacob the father of Judah and his brothers,
    Judah the father of Perez and Zerah by Tamar, Perez the father of Hezron, Hezron the father of Ram,
    Ram was the father of Amminadab, Amminadab the father of Nahshon, Nahshon the father of Salmon,
    Salmon was the father of Boaz by Rahab, Boaz the father of Obed by Ruth, Obed the father of Jesse, and
    Jesse was the father of David the king….

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *