代码之家  ›  专栏  ›  技术社区  ›  pantherfan

如何限制使用XSLT将文本拉入文本文件?

  •  0
  • pantherfan  · 技术社区  · 2 年前

    我使用XSLT脚本将HTML文件中的内容拉入.txt文件。在这种情况下,它在 <li property="ktp:answer" 以及 <section class="ktp-explanation jasper-exclude" property="ktp:explanation" typeof="ktp:Explanation"> 。我只想把文本拉到 <li> 。我该怎么做?

    以下是HTML输入的片段:

    <li property="ktp:answer" typeof="ktp:Answer">Encourage the client to increase
                            fluid intake. <section class="ktp-explanation jasper-exclude"
                                property="ktp:explanation" typeof="ktp:Explanation">
                                <section class="ktp-explanation-section jasper-exclude"
                                    data-title="Feedback" property="ktp:explanation-section"
                                    typeof="ktp:feedback">
                                    <p>While increasing fluid intake is important for both prevention
                                        and treatment of urinary tract infections (UTIs), it is not a
                                        priority over obtaining assessment data to confirm the suspected
                                        UTI. Fluids may be encouraged by the nurse after bacteria are
                                        determined to be present in the urine. </p>
                                </section>
                            </section>
                        </li>
    

    以下是我的XSLT脚本中需要修改的部分:

    <xsl:when test="$colname = 'Answers'">
          <xsl:for-each select="../../../xhtml:ol[contains(@class, 'ktp-answer-set')]/xhtml:li[@property = 'ktp:answer']">
             <xsl:value-of select="concat(' (', string(position()), ') ', normalize-space(.), '|')" />
          </xsl:for-each>
    </xsl:when>
    

    我的输出如下:

    (1) 鼓励客户增加液体摄入。虽然增加液体摄入对预防和治疗尿路感染(UTI)都很重要,但它并不是获得评估数据来确认疑似UTI的优先事项。在确定尿液中存在细菌后,护士可以鼓励液体。

    我只需要这样:

    (1) 鼓励客户增加液体摄入。

    谢谢你的帮助!

    1 回复  |  直到 2 年前
        1
  •  1
  •   Daniel Haley    2 年前

    尝试更改 normalize-space() 在:

    <xsl:value-of select="concat(' (', string(position()), ') ', normalize-space(.), '|')" />
    

    收件人:

    <xsl:value-of select="concat(' (', string(position()), ') ', normalize-space(text()[1]), '|')" />
    

    因此,您只对第一个直接子节点的空间进行规范化,而不是对上下文中的整个元素进行规范化。