I seemed to have made some progress with XSLT, but I'm still finding it very hard to transform nested XML. The XML looks as follows:
<transcription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.livesandletters.ac.uk/schema/aor2_18112016.xsd">
<page filename="00000005.tif" reader="Harvey" pagination="title page"/>
<annotation>
<marginalia hand="Italian">
<language ident="LA">
<position place="head" book_orientation="0">
<marginalia_text>gratum opus agricolis.</marginalia_text>
</position>
</language>
<translation>The pleasant work for the husbandman.</translation>
</marginalia>
</annotation>
</transcription>
By retaining some elements and attributes and modifying others I want to slightly transform this to:
<transcription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.livesandletters.ac.uk/schema/aor2_18112016.xsd">
<page filename="00000005.tif" reader="Harvey" pagination="title page"/>
<annotation>
<addition>
<hand hands="Italian">
<language ident="LA">
<position place="head" book_orientation="0">
<note>gratum opus agricolis.</note>
</position>
</language>
<translation>The pleasant work for the husbandman.</translation>
</addition>
</annotation>
</transcription>
I have generated this XSL so far, but for some reason it won't copy the properties of the position element nor the content of the marginalia_text element (which becomes the note element in the transformed XML file). Any idea what I'm doing wrong? I thought about referring to various templates, but this doesn't work either...
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="marginalia">
<additions>
<xsl:element name="hand">
<xsl:attribute name="hands"><xsl:value-of select="@hand"/></xsl:attribute>
<xsl:element name="position">
<xsl:attribute name="place"><xsl:value-of select="@place" /></xsl:attribute>
<xsl:attribute name="book_orientation"><xsl:value-of select="@book_orientation" />
</xsl:attribute>
<xsl:element name="note"><xsl:value-of select="marginalia_text"/>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:element name="translation"><xsl:value-of select="translation"/></xsl:element>
</additions>
</xsl:template>
</xsl:stylesheet>