Using XSLT to create XSL-FO with nested bold/italic tags

廉价感情. 提交于 2019-11-30 20:16:37

Look at this example. It clearly shows how to hanlde inline nodes.

[XSLT 1.0]

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>

    <xsl:template match="doc">
        <fo:root>
            <fo:page-sequence>
                <fo:flow>
                    <xsl:apply-templates select="par/point"/>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="point">
        <fo:block font-size="16pt" space-after="5mm">
            <xsl:apply-templates select="node()"/>
        </fo:block>
    </xsl:template>

    <xsl:template match="bold">
        <fo:inline font-weight="bold">
            <xsl:apply-templates select="node()"/>
        </fo:inline>  
    </xsl:template>

    <xsl:template match="italic">
        <fo:inline font-style="italic">
            <xsl:apply-templates select="node()"/>
        </fo:inline>
    </xsl:template>

</xsl:stylesheet>

given:

<doc>
    <par>
        <point>
            <text>some <bold>bold</bold></text>
        </point>
    </par>
    <par>
        <point>
            <text>some <italic>italic <bold>bolded</bold></italic></text>
        </point>
    </par>
</doc>

produces:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:page-sequence>
      <fo:flow>
         <fo:block font-size="16pt" space-after="5mm">
            some <fo:inline font-weight="bold">bold</fo:inline>
               </fo:block>
         <fo:block font-size="16pt" space-after="5mm">
            some <fo:inline font-style="italic">italic <fo:inline font-weight="bold">bolded</fo:inline>
            </fo:inline>
               </fo:block>
      </fo:flow>
   </fo:page-sequence>
</fo:root>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!