css - 如何使用 XSL 在 XML 中的特定 td 中保留新行和空格

标签 css xml xslt

enter image description here我正在尝试仅为使用 XSL 在 XML 中具有随机 id 的特定 td 保留新行和空格

所以基本上我想在 td 中保留新行,其中有一些大文本,如下所示

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href=new.xsl'?>
  <document>
    <div>
      <table width="100%" border="1">
        <thead>
          <tr>
            <th>ID</th>
            <th>Date</th>
            <th>Data Source</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>123123</td>
            <td>03/20/2018 04:49:40 PM MST</td>
            <td>Test Source</td>
          </tr>
          <tr>
            <td id="random_id_notes" colspan="3">Patient Information Name: Test, FIRST NAME Age: 108 Years DOB: 01/11/1911 Sex: Female First Para# Him boisterous invitation dispatched had connection inhabiting projection. By mutual an mr danger garret edward an. Diverted as strictly exertion
              addition no disposal by stanhill. This call wife do so sigh no gate felt. You and abode spite order get. Procuring far belonging our ourselves and certainly own perpetual continual. It elsewhere of sometimes or my certainty. Lain no as five
              or at high. Everything travelling set how law literature. Sec para# But why smiling man her imagine married. Chiefly can man her out believe manners cottage colonel unknown. Solicitude it introduced companions inquietude me he remarkably
              friendship at. My almost or horses period. Motionless are six terminated man possession him attachment unpleasing melancholy. Sir smile arose one share. No abroad in easily relied an whence lovers temper by. Looked wisdom common he an be
              giving length mr. Good #Third Para Home Call park out she wife face mean. Invitation excellence imprudence understood it continuing to. Ye show done an into. Fifteen winding related may hearted colonel are way studied. County suffer twenty
              or marked no moment in he. Meet shew or said like he. Valley silent cannot things so remain oh to elinor. Far merits season better tended any age hunted.

            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </document>

我尝试过的 XSL 但它正在影响我不想要的所有 td

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n1="urn:hl7-org:v3" xmlns:in="urn:lantana-com:inline-variable-data" xmlns:sdtc="urn:hl7-org:sdtc">
    <xsl:output method="html" indent="yes" version="4.01" encoding="ISO-8859-1" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
    <xsl:template match="n1:td">
            <span class="content_span">
                <xsl:apply-templates select="@styleCode"/>
                  <xsl:value-of select="." disable-output-escaping="yes"/>
            </span>
        </xsl:template>

使用了 CSS

 .content_span{
 font-family: Verdana, Tahoma, sans-serif; 
 display: inline; 
 white-space: pre;
}

最佳答案

如果您想保留空格,我会避免使用 indent="yes"

在 XSLT 3.0 中,您可以使用 suppress-indentation="td" 为特定元素类型覆盖 indent="yes",但即便如此您也不能为特定元素实例这样做。

但是,我不能 100% 确定这是您的问题。事实上,我不是 100% 确定我理解你的要求。您是否希望 XML 中每行文本开头的 12 个空格在呈现的 HTML 中可见?

一些其他评论:

(a) 我不知道“n1”命名空间前缀试图实现什么

(b) disable-output-escaping 不是魔法仙尘。除非您确切知道它的作用,否则不要使用它。在您的特定情况下,没有任何东西可以转义,因此禁用转义无效。

(c) 在 XML 中使用 mm/dd/yyyy 日期将使您的生活变得不必要地困难。

关于css - 如何使用 XSL 在 XML 中的特定 td 中保留新行和空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55175290/

相关文章:

html - 如何使用 UL 制作水平站点地图?

html - 包装内并排的两个 div

java - JasperReports fillReport太慢且耗资源

java - TransformerConfigurationException : Could not compile stylesheet, 错误 - 无协议(protocol)

jquery - 粘性标题上的动画

javascript - 使用 gulp 创建选择性样式表

java - 如何在 spring 中找到与 spring.xml 不在同一级别的文件?

xml - 使用 gzip 编码对同一服务器内的通信有意义吗?

java - 仅通过 XSLT 从 XML 中删除特定标签的特殊字符

regex - XSL 分析标记化字符串的字符串难度