jbrehr
jbrehr

Reputation: 815

XSLT 3 multi-step transformation

Building from the transformation in this post, I'm now trying to integrate it into a two step transformation where the same node is transformed twice. Tested independent of each other, the transformations work. For reasons I don't understand, when I bring them together using modes, it's not going through the steps correctly - somehow the modes and variables are not aligned correctly? Fiddle here.

Given 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="sighting" xml:id="MS609-1214-1"><pb break="y" n="80r"/><lb break="y" n="1"/>Item. <date type="deposition_date" when="1245-07-11" xml:id="MS609-1214_depdate">Anno Domini M°CC°XL°V° II° Ydus Junii</date>.
                    <persName ref="#peire_de_saint-michel" role="dep">P<supplied reason="abbr-name">etrus</supplied> de Sancto Michaele, miles</persName>, testis juratus dixit quod vidit apud 
                    <placeName ref="#laurac_aude" type="sighting_loc">Laurac
                            <persName ref="#heretics_in_public" role="her">hereticos</persName><lb break="y" n="2"/>publice manentes</placeName> 
                    set nullam familiari<del type="expunctus" rend="after">a</del>tatem habuit cum eis. <date type="sighting_date" when="1225" datingPoint="#MS609-1214_depdate" unit="y" interval="-20">Et sunt XX anni vel circa</date>.</seg>
            </ab>
        </body>
    </text>
</TEI>

My objective is to transform this fragment:

<date type="deposition_date" when="1245-07-11" xml:id="MS609-1214_depdate">Anno Domini M°CC°XL°V° II° Ydus Junii</date>.

Into this ('moving' some text and applying analyze-string to the same node) :

<date type="deposition_date" when="1245-07-11" xml:id="MS609-1214_depdate">Anno Domini M<hi rend="sup">o</hi>CC<hi rend="sup">o</hi>XL<hi rend="sup">o</hi>V<hi rend="sup">o</hi> II<hi rend="sup">o</hi> Ydus Junii.</date>

And the rest copy without changes.

<?xml version="1.0" encoding="UTF-8"?>
<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:variable name="step-one-result">
      <xsl:apply-templates select="/" mode="step1"/>
    </xsl:variable>  
    <xsl:apply-templates select="$step-one-result" mode="step2"/>
  </xsl:template>
  
  <xsl:template match="text()[contains(.,'°')]" mode="step1">
    <xsl:analyze-string select="." regex="°">
        <xsl:matching-substring>
            <hi xmlns="http://www.tei-c.org/ns/1.0" rend="sup">o</hi>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:value-of select="."/>
        </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:template>
  
  <xsl:template match="tei:date[@type='deposition_date' and ./following-sibling::node()[1][. instance of text() and starts-with(.,'.')]]" mode="step2">
        <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()[preceding-sibling::node()[1][./self::tei:date[@type='deposition_date']]][starts-with(.,'.')]" mode="step2">
        <xsl:value-of select="substring(.,2)"/>
    </xsl:template>
            
</xsl:stylesheet>

Many thanks in advance.

Upvotes: 0

Views: 110

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

As you are pushing the whole tree through your modes, I think you forgot to declare

<xsl:mode name="step1" on-no-match="shallow-copy"/>

<xsl:mode name="step2" on-no-match="shallow-copy"/>

Upvotes: 1

Related Questions