Search code examples
htmlxmlxslt

Transform XML via XSL


I want to transform XML into HTML and I'm struggling. For some reason, I can't even get the simplest things working. This is what I'd like to achieve:

The following information should be put in the header:

  • The value of the title element
  • The value of the publicationStmt element
  • The value of the msDesc element
  • The value of the placeName element, ideally as a link based on the value of its ref attribute
  • The value of the orgName element
  • The value of the bibl element

The following information should be put in the body

  • The value of the body element

The value of the body element should be modified as follows:

  • The notes in the p element of the body element should be transformed into HTML footnotes. The footnotes should be numbered based on the value in the n attribute of the note element and should include the value of the note element. The type attribute of the note element and its value should be ignored.
  • The value of the rs elements should be turned into a link, based on the information in the attribute of the persName tag based on the identical information in the xml:id attribute of the person element and the ref attribute of the rs element.

This is the XML file I'm working with:

<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="bm-001">
   <teiHeader>
      <fileDesc>
         <titleStmt>
            <title>Hebamme an Stadt, <date when-custom="1656">[1656]</date></title>
         </titleStmt>
         <publicationStmt>
            <p>Publication Information</p>
         </publicationStmt>
         <sourceDesc>
            <msDesc>
               <msIdentifier>
                  <settlement>Mainz</settlement>
                  <repository>Stadtarchiv</repository>
                  <idno>27-350</idno>
               </msIdentifier>
               <p>Regest</p>
            </msDesc>
         </sourceDesc>
      </fileDesc>
   </teiHeader>
   <standOff>
      <listPerson>
         <person xml:id="broemser_heinrich">
            <persName ref="http://d-nb.info/gnd/133036979">
               <forename>Heinrich</forename>
               <surname>Brömser von Rüdesheim</surname>
               <note>Vizedom in Mainz 1636-1668 <rs type="bibl" ref="schrohe_verwaltung">S.
                  39</rs></note>
            </persName>
         </person>
      </listPerson>
      <listPlace>
         <place xml:id="mainz_stadt">
            <placeName ref="https://www.geonames.org/2874225/mainz.html">Mainz</placeName>
         </place>
      </listPlace>
      <listOrg>
         <org xml:id="mainz_rds">
            <orgName>Rat der Stadt Mainz</orgName>
         </org>
      </listOrg>
      <listBibl>
         <bibl xml:id="schrohe_verwaltung">Langtitel wie in spreadsheet angelegt.</bibl>
      </listBibl>
   </standOff>
   <text>
      <body>
         <p><pb n="1"/>Wohlgeborner Freyherr, auch wohledell undt gestrenger edle, ehrnveste,
            wohlgelehrte, fürsichtige ehrsame undt weyße <rs type="person" ref="#broemser_heinrich"
               >Herrn Vicedomb</rs> , Gewaltsbott , und Zwölfere deß Raths , gnädige, großg[ünstige]
            hochgeehrte Herrn.</p>

         <p>Ew[er] Gnaden, <seg>Gestr[enge] undt<note type="crit_app">korr. aus: Geltr.
               nndt</note></seg> W[eishei]ten kann ich, entß undersetzte demütig zu referiren nit
            umbgehen, waß Gestalt mein Ehewürth<note type="annotation">Ehemann</note> Johannß Kobalt
            under Ihro Gnaden Herrn Metternich Regimentt , in die 18 Jahr vor ein Officirer undt
            Leutenant bedient geweßen, nach erhaltenem Abschiedt aber vor ohngefehr 4 Jahren nache
            Heydeßheim , bürgerlichen niedergelaßen, undt ich, deßen Ehewürthin , nun in daß dritte
            Jahr zu einer Hebam daselbst vermögt undt der Zeit uff die etlich undt 60. Kindter
            empfangen.</p>
    </body>
  </text>
</TEI>

I have managed to transform some information based on this XSL:

 <!-- Match the root TEI element -->
    <xsl:template match="/tei:TEI">
        <html>
            <head>
                <!-- Transform teiHeader elements -->
                <xsl:apply-templates select="tei:teiHeader"/>
            </head>
            <body>
                <!-- Transform text elements -->
                <xsl:apply-templates select="tei:text"/>
            </body>
        </html>
    </xsl:template>
    
    <!-- Match teiHeader element -->
    <xsl:template match="tei:teiHeader">
        <h1><xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title"/></h1>
        
        <!-- Transform other elements in header 2 -->
        <h2>
            <!-- Transform publicationStmt elements -->
            <xsl:apply-templates select="tei:fileDesc/tei:publicationStmt"/>
            <!-- Transform sourceDesc elements -->
            <xsl:apply-templates select="tei:fileDesc/tei:sourceDesc"/>
            <!-- Transform placeName element as a link -->
            Placename:
            <a href="{tei:standOff/tei:listPlace/tei:place/tei:placeName/@ref}">
                <xsl:value-of select="tei:standOff/tei:listPlace/tei:place/tei:placeName"/>
            </a>
</h2>
    </xsl:template>
    
    <!-- Match titleStmt element -->
    <xsl:template match="tei:titleStmt">
        Title: <xsl:value-of select="tei:title"/>
    </xsl:template>
    
    <!-- Match publicationStmt element -->
    <xsl:template match="tei:publicationStmt">
        Publication Information: <xsl:value-of select="tei:p"/>
    </xsl:template>
    
    <!-- Match sourceDesc element -->
    <xsl:template match="tei:sourceDesc">
        <!-- Transform msDesc elements -->
        <xsl:apply-templates select="tei:msDesc"/>
    </xsl:template>
    
    <!-- Match msDesc element -->
    <xsl:template match="tei:msDesc">
        <!-- Transform msIdentifier elements -->
        <xsl:apply-templates select="tei:msIdentifier"/>
        Regest: <xsl:value-of select="tei:p"/>
    </xsl:template>
    
    <!-- Match msIdentifier element -->
    <xsl:template match="tei:msIdentifier">
        Settlement: <xsl:value-of select="tei:settlement"/>
        Repository: <xsl:value-of select="tei:repository"/>
        IDNO: <xsl:value-of select="tei:idno"/>
    </xsl:template>
</xsl:stylesheet>

However, when trying to select data from the element, it don't get any results. So far, everything else (e.g. transforming the notes) has been an epic failure as well. Any help would be much appreciated.


Solution

  • The standOff element seems a sibling of the teiHeader element so having a template matching e.g. match="tei:teiHeader" and then doing a(n implicit) child node selection tei:standOff is not going to work, you need ../tei:standOff. I haven't checked other paths.