首页 > 解决方案 > 如何使用 XSLT 将现有 HTML 文本复制到新部分?

问题描述

我正在尝试编写一个 XSLT 脚本,它将<section property="ktp:explanation-section" typeof="ktp:feedback" class="ktp-explanation-section" data-title="Feedback">从下面的 html 复制本节中的文本:

<ol class="ktp-answer-set"> 
  <li property="ktp:answer" typeof="ktp:Answer">“I cough in the morning, but it stops.”
    <section property="ktp:explanation" typeof="ktp:Explanation" class="ktp-explanation jasper-exclude"> 
      <section property="ktp:explanation-section" typeof="ktp:feedback" class="ktp-explanation-section" data-title="Feedback"> 
        <p>Captopril is an angiotensin-converting enzyme inhibitor (ACE-I) that has a dry, hacking, persistent cough as an adverse effect. The client reports a morning cough that may or may not be associated with the medication.</p> 
      </section> 
    </section> 
  </li>  
  <li property="ktp:answer" typeof="ktp:AnswerCorrect">“I am waiting to learn the results of my pregnancy test.”
    <section property="ktp:explanation" typeof="ktp:Explanation" class="ktp-explanation jasper-exclude"> 
      <section property="ktp:explanation-section" typeof="ktp:feedback" class="ktp-explanation-section" data-title="Feedback"> 
        <p>ACE-Is are contraindicated in pregnancy. There is a black box warning that states ACE-I can cause injury and even death to a developing fetus. Since the client reports waiting for the results of a pregnancy test, this should be reported immediately to the health care provider.</p> 
      </section> 
    </section> 
  </li> 
</ol>

进入一个如下所示的新部分:

<section property="ktp:explanation-section" typeof="ktp:feedback" data-title="Feedback" class="ktp-explanation-section atom-exclude"> 
  <p class="atom-exclude">1) 
    <span class="mark-false">INCORRECT</span> – Captopril is an angiotensin-converting enzyme inhibitor (ACE-I) that has a dry, hacking, persistent cough as an adverse effect. The client reports a morning cough that may or may not be associated with the medication.
  </p>  
  <p class="atom-exclude">2) 
    <span class="mark-true">CORRECT</span> – ACE-Is are contraindicated in pregnancy. There is a black box warning that states ACE-I can cause injury and even death to a developing fetus. Since the client reports waiting for the results of a pregnancy test, this should be reported immediately to the health care provider.
  </p> 
</section>

我需要在我的 XSLT 脚本中包含哪些内容才能将该文本复制到新部分中?我可以用 1)、2) 等给每个人编号吗?

在我使用的样式表下方:

<xsl:template match="xhtml:section[@property = 'ktp:explanation']">
        <xsl:param name="content-item-name"/>

        <!-- Tab 1: Decision Tree -->  
        <section>
            <xsl:apply-templates select="@*"/>
            <xsl:choose>
                <xsl:when test="$content-item-name = $input-qid">

            <section property="ktp:explanation-section" typeof="ktp:feedback" data-title="Feedback"
                class="ktp-explanation-section atom-exclude">
                <xsl:for-each select="//xhtml:section[property='ktp:explanation-section']/p">
                    <p class="atom-exclude">
                        <xsl:apply-templates select="@*"/>
                    </p>
                </xsl:for-each>
            </section>
            <xsl:apply-templates select="node() except xhtml:section[@data-title = 'Feedback']"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates/>
                </xsl:otherwise>
            </xsl:choose> 
        </section>
    </xsl:template>

标签: xslt

解决方案


推荐阅读