R – How to import attributes and elements from XML to Filemaker

filemakerxmlxpathxslt

I have an application that stores its user database to an XML file and I need to export selected fields to Filemaker so my client and mine the data on Filemaker. I managed to make XSLT file to import XML elements, but cannot seem to find a way to import any elements. Pointers in solving this problem are greatly anticipated.

Example of the XML-file:

<?xml version="1.0" encoding="utf-8"?>
<APPLICATION_NAME>
  <USERS>
    <USER>
      <ID>15001</ID>
      <USERNAME>Administrator</USERNAME>
      <!-- other elements -->
      <PROPERTYBAG>
        <ITEM NAME="LastModifiedDate" VALUE="Fri, 05 Sep 2008 13:13:16 GMT"/>
        <ITEM NAME="Registered" VALUE="5.9.2008 16:13:16"/>
        <!-- other elements -->
      </PROPERTYBAG>
    </USER>
    <!-- more users -->
  </USERS>
</APPLICATION_NAME>

So far I've managed to import elements by following instruction from this site: http://edoshin.skeletonkey.com/2005/10/use_modular_xsl.html

And here is the XSLT that imports those elements but not attributes:

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

<xsl:include href="FileMaker.xslt"/>

<xsl:template match="/">
  <xsl:call-template name="TABLE">
    <xsl:with-param name="METADATA-FIELDS">
      <xsl:call-template name="FIELD">
        <xsl:with-param name="NAME" select="'ID'"/>
      </xsl:call-template>
      <xsl:call-template name="FIELD">
        <xsl:with-param name="NAME" select="'USERNAME'"/>
      </xsl:call-template>
      <xsl:call-template name="FIELD">
        <xsl:with-param name="NAME" select="'ISADMINISTRATOR'"/>
      </xsl:call-template>
      <xsl:call-template name="FIELD">
        <xsl:with-param name="NAME" select="'LastModifiedDate'"/>
      </xsl:call-template>
      <xsl:call-template name="FIELD">
        <xsl:with-param name="NAME" select="'Registered'"/>
      </xsl:call-template>
    </xsl:with-param>

    <xsl:with-param name="RESULTSET-RECORDS">
      <xsl:for-each select="//USER">
        <xsl:call-template name="ROW">
          <xsl:with-param name="COLS">
            <xsl:call-template name="COL">
              <xsl:with-param name="DATA" select="ID"/>
            </xsl:call-template>
            <xsl:call-template name="COL">
              <xsl:with-param name="DATA" select="USERNAME"/>
            </xsl:call-template>
            <xsl:call-template name="COL">
              <xsl:with-param name="DATA" select="ACCOUNT/ISADMINISTRATOR"/>
            </xsl:call-template>

                <xsl:call-template name="COL">
              <xsl:with-param name="DATA" select="@Registered"/>
            </xsl:call-template>

                </xsl:with-param>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:with-param>
  </xsl:call-template>
</xsl:template>

</xsl:stylesheet>

Best Answer

I have to say I'm not sure I understood what you need here.
If I did understand - you are not getting the value of

<ITEM NAME="LastModifiedDate" VALUE="Fri, 05 Sep 2008 13:13:16 GMT"/>

by using

<xsl:call-template name="COL">
      <xsl:with-param name="DATA" select="@Registered"/>
</xsl:call-template>


Edit:
If this is the case then try using ITEM/@Registered like so:

<xsl:call-template name="COL">
    <xsl:with-param name="DATA" select="PROPERTYBAG/ITEM[@NAME='Registered']/@VALUE"/>
</xsl:call-template>

you want the value attribute of ITEM element with name attribute equals Registered under propertybag element that is under each user...


Original:
If this is the case then try using ITEM/@Registered like so:

<xsl:call-template name="COL">
     <xsl:with-param name="DATA" select="ITEM/@Registered"/>
</xsl:call-template>

you want the ITEM that is under each user...

Related Topic