XSLT将Zotero xml输出转换为FMPXMLRESULT xml? [英] XSLT to translate Zotero xml output to FMPXMLRESULT xml?

查看:47
本文介绍了XSLT将Zotero xml输出转换为FMPXMLRESULT xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to get items from a Zotero database into FileMaker Pro. The most obvious way to do that is to export from Zotero into xml, translate that xml into the FMPXMLRESULT xml format, and then import into FileMaker Pro.

我是处理xml格式转换的完全新手.

I'm a complete newbie to dealing with translating xml formats.

有人有xslt可以做到这一点,还是为我提供针对这两种xml格式的一些建议(不仅仅是通用的xslt/xml引用)?

Does anybody have an xslt that will do that, or to provide me with some suggestions specific to these two xml formats (not just general xslt/xml references)?

Zotero xml输出采用国会图书馆MODS格式: http://www.loc. gov/standards/mods/.

The Zotero xml output is in the Library of Congress MODS form: http://www.loc.gov/standards/mods/.

此处描述了FileMaker Pro FMPXMLRESULT xml格式: http://www. filemaker.com/help/html/import_export.16.30.html .

The FileMaker Pro FMPXMLRESULT xml format is described here: http://www.filemaker.com/help/html/import_export.16.30.html.

以下是Zotero MODS导出的示例. (很抱歉,在这篇文章中,某些缩进在复制文件以形成代码块时丢失了.这是指向实际文件的Dropbox链接:

Below is an example of the Zotero MODS export. (Sorry, some of the indenting got lost in copying the file to form a code block in this post. Here's a Dropbox link to the actual file: 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>

推荐答案

所以它就像书目.好吧,这取决于您要如何在FileMaker中使用它.基本的FileMaker XSLT将像这样:

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>

这应该导入标题. template match="/"类似于C中的main(),它是(典型)入口点.到达那里后,我们将输出生成的XML的框架.

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.

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

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.

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

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.

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

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 :)

这篇关于XSLT将Zotero xml输出转换为FMPXMLRESULT xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆