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

白色空间的剥离似乎被打破了

  •  0
  • MitchBroadhead  · 技术社区  · 6 年前

    由于更好的Java兼容性,我正在将一些XSLT模板移动到freemarker,但是freemarker似乎在处理空白方面有问题。XML的结果是到处都是空白,如下所示:

    </fo:block>
    
    </fo:table-cell>
    </fo:table-row>
        <fo:table-row>  <fo:table-cell  
    
    
    
    >   <fo:block >
        <fo:inline  font-weight="bold"
    

    strip_whitespace=true 但没有效果。它是默认的,所以它可能已经开始工作了。

    <xsl:text> example text including padding </xsl:text> 元素。

    更新 :下面是freemarker模板的一部分示例,它在其中生成 fo:table-cell

    <#macro tableHeaderM tableHeader>
        <#list tableHeader.columns as column><@columnM column=column /></#list>
    </#macro>
    <#macro columnM column>
        <fo:table-column column-width="${column.width}cm" />
    </#macro>
    <#macro rowM row table>
        <fo:table-row><#list row.cells as cell><@cellM cell=cell table=table /></#list></fo:table-row>
    </#macro>
    <#macro cellM cell table>
        <fo:table-cell<@cellFormattingM cell=cell table=table />><@blockObjectsM blockObjects=cell.blockObjects /></fo:table-cell>
    </#macro>
    <#macro cellFormattingM cell table>
        <#if cell.border == true> border="0.1mm solid"</#if>
        <#if cell.pad == true> padding="3pt"</#if>
        <#if cell.shade == true> background-color="#eeeeee"</#if>
        <#if table.collapse == true> margin-top="5px"</#if>
    </#macro>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   ddekany    6 年前

    FreeMarker中的空格剥离和修剪仅用于删除模板本身中的空格(即,为源代码格式添加的空格)。案例中的空白区域出现在数据模型中。不幸的是,您需要预先处理DOM以除去那些(或者使用 ?trim 等等)。FreeMarker DOM包装器不知道哪些空白是无关紧要的。

    更新 (因为空白不是来自DOM): strip_whitespace (空白条)默认为 true <#t> (也许 <#rt> <#lt> )以显式删除更多空白。