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

时间:2019-03-15 03:53:21

标签: 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;
}

1 个答案:

答案 0 :(得分:1)

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

在XSLT 3.0中,您可以使用suppress-indentation="td"对特定元素类型覆盖indent =“ yes”,但即使如此,您也无法对特定元素实例执行此操作。

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

其他一些评论:

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

(b)disable-output-escapeing不是魔术仙尘。除非您确切知道它的作用,否则不要使用它。在您的特定情况下,没有什么可以逃避的,因此禁用转义没有任何作用。

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