XML上的XSLT中断HTML输出中的blockquote



我在XML上的XSL变换中的HTML输出有问题。在XML中,您可以看到段落中间有一个页面断开

。此时,样式表插入了视觉页面中断,但这打破了整个段落的格式。页面断开后出现的线条正确地缩进了,但是线间距太近,看起来与普通段落相同。有什么方法可以在没有重大大修的情况下解决此问题?

我相信我已经包含了所有相关代码:

开始XML

<floatingText xml:id="foo.001" type="bar">
<opener>
    <address>
        <addrLine>Address</addrLine>
        <addrLine>
            <date when="2017-04-26">April 26, 2017</date>
        </addrLine>
    </address>
    <salute>
        <hi rend="italic">Hello world.</hi>
    </salute>
</opener>
<body>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Pellentesque eget odio<pb type="recto" n="19"/> pellentesque, mollis 
mi et, malesuada
        est. Duis eleifend ullamcorper justo, vitae accumsan ante 
porta id.</p>
    <closer>
        <salute>Yours,</salute>
        <signed>Me</signed>
    </closer>
</body>
</floatingText>

结束XML

开始XSL变换

<xsl:template match="pb[@n]">
<LEFT>
    <table>
        <tr>
            <td>&#160;</td>
        </tr>
        <tr>
            <td style="white-space: nowrap"> - - - - - - - - - - - - 
- - - - - -
                <font face="Arial" size="-2">
                    [Begin&#160;page&#160;<xsl:value-of select="@n"
                    />]</font> - - - - - - - - - - - - - - - - - - 
</td>
        </tr>
        <tr>
            <td height="10">&#160;</td>
        </tr>
    </table>
</LEFT>
</xsl:template>
<xsl:template match="p">
<xsl:choose>
    <xsl:when test="@rend = 'center'">
        <p/>
        <font face="Arial Unicode MS, sans-serif" size="-1">
            <center>
                <xsl:apply-templates/>
            </center>
        </font>
    </xsl:when>
    <xsl:otherwise>
        <font face="Arial Unicode MS, sans-serif" size="-1">
            <p/>&#160;&#160;&#160;&#160;&#160;<xsl:apply-templates/>
        </font>
    </xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="closer | opener | dateline">
<font face="Arial Unicode MS, sans-serif" size="-1">
    <blockquote>
        <xsl:apply-templates/>
        <br/>
    </blockquote>
</font>
</xsl:template>
<xsl:template match="salute | signed">
<font face="Arial Unicode MS, sans-serif" size="-1">
    <p/>
    <br/>
    <xsl:apply-templates/>
    <br/>
</font>
</xsl:template>
<xsl:template match="floatingText[@type = 'letter']">
<blockquote>
    <font face="Arial Unicode MS, sans-serif" size="-1">
        <xsl:apply-templates/>
    </font>
</blockquote>
</xsl:template>

结束XSL

开始HTML输出

<font xmlns="" face="Arial Unicode MS, sans-serif" size="-1">
<blockquote>
    <font face="Arial Unicode MS, sans-serif" size="-1">
        <font face="Arial Unicode MS, sans-serif" size="-1">
            <blockquote>
                <font face="Arial Unicode MS, sans-serif" size="-1">
                    <br />Address
                </font>
                <font face="Arial Unicode MS, sans-serif" size="-1">
<br /> April 26, 2017.
                </font>
                <font face="Arial Unicode MS, sans-serif" size="-1">
<p /><br /> 
                    <font face="Arial, sans-serif"><i>Hello world.
</i>
                    </font><br />
                </font><br />
            </blockquote>
        </font>
        <font face="Arial Unicode MS, sans-serif" size="-1">
            <p />&#160;&#160;&#160;&#160;&#160;Lorem ipsum dolor sit 
amet, consectetur adipiscing elit. Pellentesque posuere, erat non 
commodo ornare, nunc nulla faucibus mauris, quis venenatis urna 
turpis eu lorem. Pellentesque eget odio
            <CENTER>
                <table>
                    <tr>
                        <td>&#160;
                        </td>
                    </tr>
                    <tr>
                        <td style="white-space: nowrap">
                            <font face="Arial" size="-2">
[dashes are here]&#160;begin&#160;page&#160;19&#160;[dashes are here]
                            </font>
                        </td>
                    </tr>
                    <tr>
                        <td height="10">&#160;
                        </td>
                    </tr>
                </table>
            </CENTER>
            pellentesque, mollis mi et, malesuada est. Duis eleifend 
ullamcorper justo, vitae accumsan ante porta id.
        </font>
        <font face="Arial Unicode MS, sans-serif" size="-1">
            <blockquote>
                <font face="Arial Unicode MS, sans-serif" size="-1">
<p /><br />Yours,<br /></font>
                <font face="Arial Unicode MS, sans-serif" size="-1">
<p /><br />Me<br />
                </font><br />
            </blockquote>
        </font>
    </font>
</blockquote>
</font>

结束HTML

一种简单的方法是渲染&lt; p&gt;单独:

<xsl:template match="p//text()">
    <font face="Arial Unicode MS, sans-serif" size="-1">
        <xsl:value-of select="."/>
    </font>
</xsl:template>

但是,这可能会影响p的其他后代的渲染,例如hi等。您将必须针对此类元素介绍单独的模板。

在@friedemann_bach的评论上展开,这是我们要做的:我们在常规文本流中插入一个管道符号,然后将DIV插入,然后将其移动到正确的位置(在一个左侧的边缘柱(通过CSS。这是XSLT:

<xsl:template match="pb">
    <xsl:choose>
        <xsl:when test="@break='no'">
            <xsl:text>|</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:text> | </xsl:text>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:element name="div">
        <xsl:attribute name="class">pageNumbers</xsl:attribute>
        <xsl:value-of select="concat('p. ', @n)"/>
    </xsl:element>
</xsl:template>

和style.css:

.pageNumbers {
    float: left;
    margin-left: -12%;
    display: block;
}

最新更新