如何从我的 XML 创建一个 "quasi csv"?

How can I create a "quasi csv" from my XML?

我正在尝试获取 TEI-XML 中看起来或多或少像这样的所有 <ref type="biblical"/>(来自项目的 header,其中包含一个包含 <ref type="biblical" cRef=""> 的特定段落:

<?xml version="1.0" encoding="utf-8"?>

<!--<?xml-model href="../Customization/Schema_Quellentexte/religionsfrieden-quellentexte.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>--> <?xml-model href=""http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="edoc_ed000227_fg_augsburger_interim_zdt">
   
   
   <teiHeader>      
      <fileDesc>         
         <titleStmt>
            <title level="s">Europäische Religionsfrieden Digital</title>
            <title level="a">Augsburger Interim (15.&#x00A0;Mai&#x00A0;/ 30.&#x00A0;Juni 1548) - Deutscher Text</title>
            <principal ref="http://d-nb.info/gnd/111186870">Irene Dingel</principal> 
            <editor role="http://id.loc.gov/vocabulary/relators/edt" ref="http://orcid.org/0000-0002-1509-6960">Thomas Stäcker</editor>
            <editor role="http://id.loc.gov/vocabulary/relators/edt" ref="https://orcid.org/0000-0002-0801-5130">Andreas Zecherle</editor> 
            <editor role="http://id.loc.gov/vocabulary/relators/mrk">Silke Kalmer</editor>           
         </titleStmt>         
         <editionStmt>
            <edition>Digitale Edition gemäß <ref target="http://www.tei-c.org/">TEI P5</ref></edition>
            <funder>Deutsche Forschungsgemeinschaft</funder>
         </editionStmt>         
         <publicationStmt>
            <publisher>
               <orgName ref="http://www.isni.org/0000000119314040">Akademie der Wissenschaften und Literatur Mainz</orgName>
            </publisher>           
            <distributor change="#ch01">
               <orgName ref="http://www.isni.org/0000000110101946">Universitäts- und Landesbibliothek Darmstadt</orgName>
               <idno type="ISIL">http://lobid.org/organisation/DE-17</idno>
            </distributor>
            <date when="2021-12-16" type="issued">2021</date>
            <availability>
               <licence target="https://creativecommons.org/licenses/by/4.0/">
                  <p xml:lang="en">This file is licensed under the terms of the Creative Commons License CC-BY 4.0 (Attribution 4.0 International)</p>
               </licence>
            </availability>
         </publicationStmt>        
         <sourceDesc><!-- bitte ausfüllen; nicht zutreffende Elemente bitte rauslöschen -->
            <msDesc>
               <msIdentifier>
                  <settlement></settlement>                               
                  <repository></repository>
                  <collection></collection>
                  <idno>Signatur</idno>
                  <idno type="urn">urn:nbn:de:gbv:3:1-254930</idno>
                  <idno type="vd16">http://gateway-bayern.de/VD16+ZV+17728</idno>
               </msIdentifier>
               <msContents>
                  <msItem>
                     <title></title>
                     <respStmt>
                        <resp></resp>
                        <persName></persName>
                     </respStmt>
                     <biblStruct><!-- gilt nur für Drucke; rausnehmen, wenn es sich um ein Manuskript handelt! -->
                        <monogr xml:id="vorlage">
                           <imprint>
                              <pubPlace ref="http://www.geonames.org/2874225/mainz.html">Mainz</pubPlace>
                              <publisher>
                                 <persName></persName>
                              </publisher>
                              <date>1548</date>
                           </imprint>
                        </monogr>
                     </biblStruct>
                  </msItem>
               </msContents>
               <history><!-- bei Manuskript, falls Datum und/oder Ort bekannt sind; andernfalls rauslöschen! -->
                  <origin>
                     <date></date>
                     <placeName></placeName>
                  </origin>
               </history>
            </msDesc>    
         </sourceDesc>
      </fileDesc>      
      <encodingDesc>         
         <projectDesc>
            <p>
               <ref target="http://www.eured.de">Europäische Religionsfrieden Digital</ref>
            </p>
         </projectDesc>
         <classDecl>
            <taxonomy xml:id="marcrelator">
               <bibl><idno type="URI">http://id.loc.gov/vocabulary/relators/</idno> MARC Code List for Relators </bibl>
            </taxonomy>
         </classDecl>         
      </encodingDesc>      
      <profileDesc>         
         <langUsage>
            <language ident="deut">Deutsch</language><!-- Sprache hinzufügen -->
         </langUsage>         
      </profileDesc>      
      <revisionDesc>
         <change xml:id="ch01" when="2018-01-18"><p>Die Edition ist 2018 von der Herzog August Bibliothek Wolfenbüttel an die Universitäts- und Landesbibliothek Darmstadt umgezogen.</p></change>
      </revisionDesc>   
   </teiHeader>
<text>
<body>

            <p facs="#facs_13_TextRegion_1624022922087_339">
               <lb facs="#facs_13_line_1624022900872_333" n="N001"/>Da nun das<note type="crit_app"><bibl><ref type="bibl" target="#mehlhausen_augsburger_interim"><surname type="editor">Mehlhausen</surname>, Augsburger Interim</ref>, S.&#x00A0;36</bibl>: des.</note> menschen gemüt dermassen wol <w>zuge<pc>-</pc>
               <lb facs="#facs_13_r2l14" n="N002"/><note place="margin-left" facs="#facs_13_TextRegion_1624023026742_369">
               <lb facs="#facs_13_r1l2" n="N001"/>Eccle. 15.</note>richtet</w> was, <q>hat in Gott gelassen inn der hand seines <w>eig<pc>-</pc>
               <lb facs="#facs_13_r2l15" n="N003"/>nen</w> Raths</q><note type="annotation"><ref type="biblical" cRef="Sir_15,14">Sir 15,14</ref>.</note>, Also weyt, das er nicht weniger macht hette
               <lb facs="#facs_13_r2l16" n="N004"/>zu wölen das gut als das böse. </p>
</body>
</text>
</TEI>

最初,我只想在第一步中从中创建一个 HTML table,我退后一步,决定先做其他事情,因为我希望它在最后一个 CSV,我想,朝着这个方向迈出的一个很好的步骤就是创建一个包含所有元素的列表。 (不是结构化列表,而是 text-file 中的 one-after-another :-D):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:tei ="http:www.tei-c.org/ns/1.0"
   exclude-result-prefixes="xs"
   version="3.0">
   <xsl:strip-space elements="*"/>
   <xsl:template match="/tei:ref[@type='biblical']">
      <!-- header -->
      <xsl:text> Kürzel&#10;</xsl:text>
      <!-- data -->
      <xsl:for-each select="tei:ref[@type='biblical']">

         <xsl:value-of select="@cRef"/>
         <xsl:text>&#10;</xsl:text>
      </xsl:for-each>
   </xsl:template>
   
</xsl:stylesheet>

我对结果有点困惑:

The source document is in namespace http://www.tei-c.org/ns/1.0, but none of the template rules match elements in this namespace (Use --suppressXsltNamespaceCheck:on to avoid this warning)

我正在通过 Oxygen 20.0 使用 Saxon-EE 9.8.0.8。 我仍在寻找使它成为 table 的方法,但我也可以为此使用 Python。 (我更喜欢 table Python!)

预期输出是所有 @cRef 属性的一部分,每个 @cRef 的内容在一行中(完整结果应包含大约 300 个条目):

Kürzel;
Sir_15,14;
{next entry}

...

我目前正在从 Covid 中恢复过来,因此很难集中注意力,所以如果我忽略了一些太平凡的事情,请保持温和! :-D

一切顺利, K

您可以通过以下方式执行此操作:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:tei ="http://www.tei-c.org/ns/1.0"
   exclude-result-prefixes="xs"
   version="3.0">
   <xsl:strip-space elements="*"/>
   
   <xsl:output method="text"/>
   
   <xsl:template match="/">
      <!-- header -->
      <xsl:text>Kürzel&#10;</xsl:text>
      <!-- data -->
      <xsl:apply-templates select="//tei:ref[@type='biblical']"/>
   </xsl:template>
   
   <xsl:template match="tei:ref[@type='biblical']">
      <xsl:value-of select="@cRef"/>
      <xsl:text>&#10;</xsl:text>
   </xsl:template>
   
</xsl:stylesheet>

看到它在这里工作:https://xsltfiddle.liberty-development.net/bF2MmYn

如果您使用的是支持 XSLT 2.0 的处理器(例如 Saxon 9.x),那么您可以简单地执行以下操作:

XSLT 2.0

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.tei-c.org/ns/1.0">
<xsl:output method="text"/>
   
<xsl:template match="/TEI">
    <xsl:text>Kürzel;&#10;</xsl:text>
    <xsl:value-of select="//ref[@type='biblical']/@cRef" separator=";&#10;"/>
</xsl:template>
  
</xsl:stylesheet>