XSLT to translate Zotero xml output to FMPXMLRESULT xml?

ぐ巨炮叔叔 提交于 2019-12-08 18:10:27

So it's like a bibliography. Well, it depends on how you want to have it in FileMaker. The basic FileMaker XSLT will be like that:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:mod="http://www.loc.gov/mods/v3"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
      <ERRORCODE>0</ERRORCODE>
      <PRODUCT NAME="N/A" BUILD="N/A" VERSION="N/A"/>
      <DATABASE NAME="N/A" LAYOUT="N/A" RECORDS="1"
        DATEFORMAT="M/d/yyyy" TIMEFORMAT="h:mm:ss a"/>
      <METADATA>
        <!-- 1 -->
        <FIELD EMPTYOK="YES" MAXREPEAT="1" TYPE="NUMBER"
            NAME="Title" />
        <!-- More field definitions -->
      </METADATA>
      <RESULTSET>
        <xsl:for-each select="mod:modsCollection/mod:mods">
          <ROW MODID="1" RECORDID="1">
            <!-- 1. Title -->
            <COL>
              <DATA>
                <xsl:value-of select="mod:titleInfo/mod:title" />
              </DATA>
            </COL>
            <!-- More COL's in the same order as the fields -->
          </ROW>
        </xsl:for-each>
      </RESULTSET>
    </FMPXMLRESULT>
  </xsl:template>
</xsl:stylesheet>

This one should import the title. The template match="/" is like main() in C, it's the (typical) entry point. Once we get there we output the skeleton of the resulting XML.

Once we get to rows, we use a XSLT instruction to loop over elements that are to be records in our table; in our case these are mod:modsCollection/mod:mods, i.e. bibliography entries, but they could be anything; for instance, we can loop over all names (//mod:name). The mod: prefix is a shortcut for the Zotero namespace (http://www.loc.gov/mods/v3); in the original XML it is specified as the default namespace, so it's used without prefix, but in the XSLT I use the FileMaker XML namespace as default (see how I specify it in the FMPXMLRESULT) and define a prefix to refer to the Zotero elements.

The looping expression is an XPath expression; google it to find the full spec. Here I used a simple expression to get me all mods elements. As I go over them I output more FileMaker stationery (ROW) and then for each field also COL and DATA. Now, for the first field's DATA I need to read title data. Since I'm in the mods element, the path to the data is titleInfo/title; to get the value I use the xsl:value-of element.

To import more fields, add more field definitions and more COLs. To import something else (e.g. not the entries, but all the people) use a different expression in xsl:for-each. This should get you started :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!