In this XML:
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="MS609-1577">
<teiHeader/>
<text>
<body>
<ab xml:id="MS609-1577-LA" xml:lang="la">
<seg type="dep_event" subtype="denial" xml:id="MS609-1577-1" sameAs="#MS609-1553"><lb break="y" n="24"/>Item.
<date type="deposition_date" sameAs="#MS609-1553" xml:id="MS609-1577_depdate">Anno <supplied>et die</supplied> predictis</date>.
<persName ref="#peire_guibert_asv-hg" role="dep">Petrus Guitberti</persName>
testis juratus dixit idem per omnia quod
<persName ref="#peire_bernart_asv-hg" role="ref">P<supplied reason="abbr-name">etrus</supplied>
Bernardi</persName>.<seg type="witnesses" sameAs="#MS609-1601"/></seg>
</ab>
</body>
</text>
</TEI>
I would like to move the full stop from outside the element <date> to the position of last child inside the element <date>. So, this fragment:
<supplied>et die</supplied> predictis</date>.
becomes:
<supplied>et die</supplied> predictis.</date>
…while everything else should be copied intact.
The following XSL puts the full stop into the required element as the last child.
However, the third template is applying the substring() to all following-sibling::text() of <date>. I only want to target the first following-sibling only in the case where it is a text() node.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="tei:date[@type='deposition_date' and ./following-sibling::node()[1][. instance of text() and starts-with(.,'.')]]">
<date xmlns="http://www.tei-c.org/ns/1.0">
<xsl:copy-of select="./@*"/>
<xsl:copy-of select="./(* | text())"/>
<xsl:text>.</xsl:text>
</date>
</xsl:template>
<xsl:template match="text()[starts-with(.,'.')][./preceding-sibling::tei:date[@type='deposition_date']]">
<xsl:value-of select="substring(.,2)"/>
</xsl:template>
</xsl:stylesheet>
Fiddle here: https://xsltfiddle.liberty-development.net/bFbBTu6/1
Many thanks in advance.
>Solution :
The fix for the third template would be
<xsl:template match="text()[starts-with(.,'.')][preceding-sibling::node()[1][self::tei:date[@type='deposition_date']]]">