我在让 XSLT 脚本不拉取<li>
原始输入文件中的标签时遇到了麻烦。请参见下面我的输出屏幕截图中红色圆圈区域:
我遇到问题的脚本部分如下:
<xsl:template match="xhtml:ol[@property = 'ktp:questionSet']">
<xsl:param name="path"/>
<xsl:variable name="content-item-name"
select="//xhtml:section/xhtml:span[@property = 'atom:content-item-name']/@data-value"/>
<li class="ktp-question" property="ktp:question" typeof="ktp:Question">
<section class="ktp-question-set-meta">
<xsl:apply-templates
select="(//xhtml:section[@class = 'ktp-meta' and not(@property = 'ktp:questionSetType')])[position() = 3 or position() = 4]"/>
</section>
<section property="ktp:stimulus" typeof="ktp:Stimulus" class="ktp-stimulus">
<xsl:apply-templates
select="xhtml:li[@class = 'ktp-stimulus']/node()"/>
</section>
<section class="ktp-question-stem">
<xsl:apply-templates
select="//xhtml:section[@class = 'ktp-question-stem']/node()"/>
</section>
<ol class="ktp-answer-set">
<xsl:apply-templates
select="//xhtml:ol[contains(@class, 'ktp-answer-set')]/node()"/>
</ol>
<section property="ktp:explanation" typeof="ktp:Explanation"
class="ktp-explanation">
<xsl:apply-templates
select="//xhtml:section[@class = 'ktp-explanation']/node()"/>
</section>
</li>
</xsl:template>
我正在处理的输入文件如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link href="../../assets/css/main.css" rel="stylesheet" title="default" type="text/css" />
<title>ptalme03</title>
</head>
<body>
<ol class="ktp-question-set" >
<li><ol property="ktp:questionSet" typeof="ktp:QuestionSet" class="ktp-question-set">
<li class="ktp-question-set-meta"><section property="ktp:metadata"
class="ktp-meta">
<span property="atom:content-item-name" class="ktp-meta"
data-value="ptalme03"></span>
</section><section property="ktp:tags" class="ktp-meta">
<span property="ktp:questionSetType" class="ktp-meta"
>shared-stimulus</span>
</section></li>
<li property="ktp:stimulus" typeof="ktp:Stimulus" class="ktp-stimulus"><p>
<img src="../../img/alpha_images_pt1/SAT_PT_math2_Q3.svg" />
</p></li>
<li property="ktp:question" typeof="ktp:Question" class="ktp-question">
<span property="atom:content-item-name" class="ktp-meta" data-value="ptalme03"></span>
<section class="ktp-question-meta">
<section class="ktp-meta" property="ktp:metadata">
<span class="ktp-meta" data-value="ptalme03"
property="atom:content-item-name"></span>
</section>
<section class="ktp-meta" property="ktp:tags">
<span class="ktp-meta" property="ktp:interactionType"
>single-select</span>
<span class="ktp-meta" property="OLD QID">ftm02.03</span>
</section>
</section><section class="ktp-question-stem">
<p>What is the <i>x</i>-intercept of the graph shown? </p>
</section><ol class="ktp-answer-set">
<li property="ktp:answer" typeof="ktp:AnswerCorrect">(−1, 0)</li>
</ol><section property="ktp:explanation" typeof="ktp:Explanation"
class="ktp-explanation">
<section class="ktp-explanation-section" data-title="Feedback"
data-uuid="e955d9441cc051f966008c9d6da75adc"
property="ktp:explanation-section" typeof="ktp:feedback">
<p><b>Getting to the Answer:</b> The <i>x</i>-intercept is the point
where the graph crosses the <i>x</i>-axis. The graph crosses the
<i>x</i>-axis at (−1, 0). <b>(A)</b> is correct. </p>
</section>
</section>
</li>
</ol>
</li>
</ol>
</body>
</html>
查看您在问题中包含的 XSLT 模板,
li
其输出中产生的唯一元素是:在您发布的输出图像中,上述元素是无属性的 unwanted 元素的子元素。因此,您在图像中圈出的 unwanted 元素不可能由您在问题中包含的模板生成。它必须由您未包含的其他模板生成。
<li>
<li>
几乎可以肯定,
<li>
输出是 的副本<li>
,它出现在输入文件中作为元素的子元素<ol class="ktp-question-set" >
,并且也是样式表省略的元素的父元素: 。<ol property="ktp:questionSet" typeof="ktp:QuestionSet" class="ktp-question-set">
我猜省略是由与 匹配的模板引起的,ol
并且在将模板应用于其子元素之前未能复制元素,因此最终将 视为li
另一个 的子元素li
。如果您确实想省略ol
,则还必须省略其父元素li
。