Reputation: 815
I am transforming a document with the objective of inserting the attribute @fn
on certain elements with an incremented count value. The count is incrementing correctly, however the attribute is not being inserted on nest elements.
In the below example I've left in a number of elements to see the eventual (possible) complexity of nesting. The Fiddle is here.
The problem is that the first <seg>
should have the attribute @fn="1"
and the first <date>
should have the attribute @fn="2"
and <note>
should have @fn="3"
. Only the <seg>
is receiving the attribute, evidently the action of copying is not working on nested elements but I don't know how to resolve this.
The original XML is:
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<text>
<body>
<ab xml:id="MS609-0017-LA" xml:lang="la">
<seg n="1" type="dep_event" subtype="event" xml:id="MS609-0017-1" corresp="#MS609-0017-1"><lb break="y" n="35"/>Item.
<date type="deposition_date" sameAs="#MS609-0013">Anno et die quo supra.</date>
Poncius de Rozengue testis juratus<note type="public">test note</note> dixit quod vidit <persName ref="#guilhem_vidal_h_lbc-au" role="her">Willelmum
Vital</persName> et socium suum, hereticos, <placeName type="event_loc" ref="#vineyard_of_joan_carabula">juxta
vineam den <persName ref="#joan_carabula_msp-au" role="ref">Johanni<pb n="3v"/><lb break="y" n="1"/>Carabula</persName></placeName>.
Et vidit ibi <persName ref="#guilhem_de_rosengue_msp-au" role="par">Willelmum de Rezenge</persName>
fratrem ipsius testis. <date type="event_date" when="1239">Et sunt<lb break="y" n="4"/>VI anni vel circa.</date></seg>
<seg n="2" type="dep_event" subtype="belief" xml:id="MS609-0017-2" corresp="#MS609-0017-2">Quisque dapibus nisl sed porta malesuada.
Proin et velit vitae urna elementum accumsan. Nam accumsan vehicula dolor, at lobortis augue.
Cras mollis scelerisque convallis.</seg>
</ab>
</body>
</text>
</TEI>
The XSL:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- set numbers to footnotes -->
<xsl:template match="tei:note[@type='public'] | tei:date[@type=('deposition_date', 'sentence_date', 'oath_date')] | tei:ab/tei:seg[@corresp ne '']">
<xsl:variable name="fn">
<xsl:number count="tei:note[@type='public'] | tei:date[@type=('deposition_date', 'sentence_date', 'oath_date')] | tei:ab/tei:seg[@corresp ne '']" format="1" level="any"/>
</xsl:variable>
<xsl:element name="{ name(.) }" namespace="http://www.tei-c.org/ns/1.0">
<xsl:copy-of select="./@*"/>
<xsl:attribute name="fn">
<xsl:value-of select="$fn"/>
</xsl:attribute>
<xsl:copy-of select="./node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
The desired result:
<?xml version="1.0" encoding="UTF-8"?><TEI xmlns="http://www.tei-c.org/ns/1.0">
<text>
<body>
<ab xml:id="MS609-0017-LA" xml:lang="la">
<seg n="1" type="dep_event" subtype="event" xml:id="MS609-0017-1" corresp="#MS609-0017-1" fn="1"><lb break="y" n="35"/>Item.
<date type="deposition_date" sameAs="#MS609-0013" fn="2">Anno et die quo supra.</date>
Poncius de Rozengue testis juratus<note type="public" fn="3">test note</note> dixit quod vidit <persName ref="#guilhem_vidal_h_lbc-au" role="her">Willelmum
Vital</persName> et socium suum, hereticos, <placeName type="event_loc" ref="#vineyard_of_joan_carabula">juxta
vineam den <persName ref="#joan_carabula_msp-au" role="ref">Johanni<pb n="3v"/><lb break="y" n="1"/>Carabula</persName></placeName>.
Et vidit ibi <persName ref="#guilhem_de_rosengue_msp-au" role="par">Willelmum de Rezenge</persName>
fratrem ipsius testis. <date type="event_date" when="1239">Et sunt<lb break="y" n="4"/>VI anni vel circa.</date></seg>
<seg n="2" type="dep_event" subtype="belief" xml:id="MS609-0017-2" corresp="#MS609-0017-2" fn="4">Quisque dapibus nisl sed porta malesuada.
Proin et velit vitae urna elementum accumsan. Nam accumsan vehicula dolor, at lobortis augue.
Cras mollis scelerisque convallis.</seg>
</ab>
</body>
</text>
</TEI>
Many thanks in advance.
Upvotes: 1
Views: 29
Reputation: 167716
Change <xsl:copy-of select="./node()"/>
to <xsl:apply-templates/>
.
Unrelated to your problem, I think instead of <xsl:element name="{ name(.) }" namespace="http://www.tei-c.org/ns/1.0">
you just want <xsl:copy>
. Unless you are trying to get rid of in-scope namespace, but in XSLT 2/3 the xsl:copy
takes copy-namespaces="no"
if you really need that.
Upvotes: 2