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

XSLT 3.0流模式下仅验证指定课程编号的开课匹配问题

XSLT 3.0流模式下指定课程校验修正方案

核心修正思路

要解决输出包含其他课程结果的问题,关键在于精准定位目标课程(编号00151744),仅对该课程的Instructor_Led_Webinar_Lesson_Data标题进行校验,同时遵循XSLT 3.0流模式的单遍读取规则。

修正后的XSLT代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- 启用流处理模式 -->
    <xsl:mode streamable="yes"/>

    <!-- 累加器:缓存Offerings中所有开课的标题,供后续校验使用 -->
    <xsl:accumulator name="offering-titles" as="xs:string*" initial-value="()">
        <xsl:accumulator-rule match="Offerings/Offering/Title" select="$value || string(.)"/>
    </xsl:accumulator>

    <!-- 主模板:匹配根节点,仅处理目标课程 -->
    <xsl:template match="/">
        <ErrorReport>
            <!-- 精准定位课程编号为00151744的课程节点 -->
            <xsl:apply-templates select="AllCourses/Course[CourseNumber='00151744']/Instructor_Led_Webinar_Lesson_Data"/>
        </ErrorReport>
    </xsl:template>

    <!-- 处理目标课程的每个课程标题,校验是否存在对应开课记录 -->
    <xsl:template match="Instructor_Led_Webinar_Lesson_Data">
        <xsl:for-each select="LessonTitle">
            <xsl:variable name="current-lesson-title" select="string(.)"/>
            <!-- 对比缓存的开课标题,输出未匹配错误 -->
            <xsl:if test="not($current-lesson-title = accumulator-before('offering-titles'))">
                <UnmatchedLesson>
                    <CourseNumber>00151744</CourseNumber>
                    <UnmatchedLessonTitle><xsl:value-of select="$current-lesson-title"/></UnmatchedLessonTitle>
                    <ErrorInfo>该课程标题在Offerings中无对应开课记录</ErrorInfo>
                </UnmatchedLesson>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

关键修正点说明

  • 精准过滤目标课程:通过Course[CourseNumber='00151744']直接定位目标课程,避免遍历所有课程节点,从根源排除其他课程的干扰。
  • 流模式兼容处理:使用XSLT 3.0的累加器(xsl:accumulator)缓存Offerings的开课标题,满足流模式下仅能单遍读取源文档的要求。
  • 聚焦目标节点处理:仅对目标课程下的Instructor_Led_Webinar_Lesson_Data节点应用模板,确保校验范围严格限定在目标课程内。

内容的提问来源于stack exchange,提问作者Chris Tucker 2016

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 12:21:13