You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSLT 3多步骤转换模式整合异常排查求助

XSLT 3 两步转换整合问题排查

我参考相关转换逻辑,尝试将两个独立可正常运行的转换整合为XSLT 3两步转换,对同一节点执行两次处理。但使用mode整合后流程未按预期执行,疑似模式与变量未正确匹配。

给定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>

转换目标

需将以下片段:

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

转换为:

<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>

其余内容保持不变。

当前使用的XSLT代码

<?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>

恳请协助排查问题,非常感谢!

内容的提问来源于stack exchange,提问作者jbrehr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 04:03:03