XSLT将Zotero xml输出转换为FMPXMLRESULT xml?

时间:2012-08-26 17:50:15

标签: xml xslt filemaker

我需要将Zotero数据库中的项目导入FileMaker Pro。最明显的方法是从Zotero导出到xml,将该xml转换为FMPXMLRESULT xml格式,然后导入到FileMaker Pro中。

我是处理翻译xml格式的完全新手。

有没有人会有这样做的xslt,或者为我提供一些特定于这两种xml格式的建议(不仅仅是一般的xslt / xml参考)?

Zotero xml输出位于美国国会图书馆MODS表格中:http://www.loc.gov/standards/mods/

FileMaker Pro FMPXMLRESULT xml格式如下所述:http://www.filemaker.com/help/html/import_export.16.30.html

以下是Zotero MODS导出的示例。 (对不起,在这篇文章中复制文件以形成代码块时,一些缩进文件丢失了。这是一个指向实际文件的Dropbox链接:https://www.dropbox.com/s/otrwr7xk0uwmff7/From_Zotero_MODS.xml

<?xml version="1.0"?>
<modsCollection xsi:schemaLocation="http://www.loc.gov/mods/v3     
http://www.loc.gov/standards/mods/v3/mods-3-2.xsd" xmlns="http://www.loc.gov/mods/v3"     
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <mods>
<titleInfo>
  <title>Roberto Giobbi's Card college. Volume 1</title>
</titleInfo>
<typeOfResource>text</typeOfResource>
<genre authority="local">book</genre>
<genre authority="marcgt">book</genre>
<name type="personal">
  <namePart type="family">Giobbi</namePart>
  <namePart type="given">Roberto</namePart>
  <role>
    <roleTerm type="code" authority="marcrelator">aut</roleTerm>
  </role>
</name>
<originInfo>
  <place>
    <placeTerm type="text">Seattle, Wash.</placeTerm>
  </place>
  <publisher>Hermetic Press</publisher>
  <copyrightDate>1996</copyrightDate>
  <issuance>monographic</issuance>
</originInfo>
<identifier type="isbn">0945296185</identifier>
<subject>
  <topic>Card tricks</topic>
</subject>
<note>External Resources: Cite This Item Search for versions with same title and author     
| Advanced options ...
Uniform Title: Grosse kartenschule. Band 1. English
Edition: Rev. 2nd ed. ; English language ed.
Language: English
Note(s): Includes bibliographical references (p. [245]-247) and index.
Other Titles: Card college
Responsibility: illustrated by Barbara Giobbi-Ebnöther ; translated from the German by     
Richard Hatch.
Vendor Info: Baker &amp; Taylor YBP Library Services (BKTY YANK) 32.00 Status:                 
active Note:               B&amp;T Title: Card College
Entry: 19960709
Update: 20091103
Provider: OCLC</note>
</mods>
<mods>
<titleInfo>
  <title>Book of magic.</title>
</titleInfo>
<typeOfResource>text</typeOfResource>
<genre authority="local">book</genre>
<genre authority="marcgt">book</genre>
<name type="personal">
  <namePart type="family">Warlock</namePart>
  <namePart type="given">Peter</namePart>
  <role>
    <roleTerm type="code" authority="marcrelator">aut</roleTerm>
  </role>
</name>
<originInfo>
  <publisher>London New York, Arco</publisher>
  <copyrightDate>1956</copyrightDate>
  <issuance>monographic</issuance>
</originInfo>
<subject>
  <topic>Magic tricks</topic>
</subject>
<note>External Resources: Cite This Item Search for versions with same title and author  
| Advanced options ...
Edition: [1st ed.]
Language: English
Class Descriptors: LC: GV1547; Dewey: 793.8
Entry: 19750729
Update: 20120116
Provider: OCLC</note>
</mods>
<mods>
<titleInfo>
  <title>The amateur magician's handbook,</title>
</titleInfo>
<typeOfResource>text</typeOfResource>
<genre authority="local">book</genre>
<genre authority="marcgt">book</genre>
<name type="personal">
  <namePart type="family">Hay, Henry</namePart>
  <namePart type="given"/>
  <role>
    <roleTerm type="code" authority="marcrelator">aut</roleTerm>
  </role>
</name>
<name type="personal">
  <namePart type="family">Mussey</namePart>
  <namePart type="given">June Barrows</namePart>
  <role>
    <roleTerm type="code" authority="marcrelator">aut</roleTerm>
  </role>
</name>
<originInfo>
  <publisher>New York, Crowell</publisher>
  <copyrightDate>1972</copyrightDate>
  <issuance>monographic</issuance>
</originInfo>
<identifier type="isbn">0690057113</identifier>
<subject>
  <topic>Magic tricks</topic>
</subject>
<note>External Resources: Cite This Item Search for versions with same title and author 
| Advanced options ...
Edition: 3d ed., rev. and expanded.
Language: English
Note(s): Bibliography: p. 365-373.
Class Descriptors: LC: GV1547; Dewey: 793.8
Responsibility: by Henry Hay. Photos. by Audrey Alley.
Vendor Info: Baker and Taylor (BTCP)
Entry: 19720814
Update: 20080829
Provider: OCLC</note>
</mods>
</modsCollection>

1 个答案:

答案 0 :(得分:1)

所以它就像一个参考书目。嗯,这取决于你希望如何在FileMaker中拥有它。基本的FileMaker XSLT就是这样的:

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

这个应该导入标题。 template match="/"与C中的main()类似,它是(典型的)入口点。一旦到达那里,我们输出生成的XML的骨架。

一旦我们到达行,我们使用XSLT指令来循环遍历我们表中记录的元素;在我们的例子中,这些是mod:modsCollection/mod:mods,即参考书目条目,但它们可以是任何东西;例如,我们可以遍历所有名称(//mod:name)。 mod:前缀是Zotero命名空间的快捷方式(http://www.loc.gov/mods/v3);在原始XML中,它被指定为默认命名空间,因此它在没有前缀的情况下使用,但在XSLT中我使用FileMaker XML命名空间作为默认值(请参阅我在FMPXMLRESULT中如何指定它)并定义前缀以引用对Zotero元素。

循环表达式是一个XPath表达式;谷歌它找到完整的规格。在这里,我使用一个简单的表达式来获取所有mods个元素。当我查看它们时,我会输出更多FileMaker信纸(ROW),然后为每个字段输出COLDATA。现在,对于第一个字段DATA,我需要读取标题数据。由于我在mods元素中,因此数据路径为titleInfo/title;获取值我使用xsl:value-of元素。

要导入更多字段,请添加更多字段定义和更多COL。要导入其他内容(例如,不是条目,而是所有人),请在xsl:for-each中使用不同的表达式。这应该让你开始:)