Xml 使用xpath和/或xsl fo设置斜体/粗体标记的格式

Xml 使用xpath和/或xsl fo设置斜体/粗体标记的格式,xml,xslt,xpath,xsl-fo,Xml,Xslt,Xpath,Xsl Fo,我有一个类似的问题,比如这个问题:。我想检测XML文本中的和标记,并用XSLT正确格式化。 我试着把它当作另一个问题的解决方案,但似乎对我不起作用。我错过了什么 这是我的XML结构: <bibliography> <type1> Some text and <italic>italic Text</italic> and <bold>bold text</bold> </type1>

我有一个类似的问题,比如这个问题:。我想检测XML文本中的
标记,并用XSLT正确格式化。 我试着把它当作另一个问题的解决方案,但似乎对我不起作用。我错过了什么

这是我的XML结构:

<bibliography>
    <type1>
        Some text and <italic>italic Text</italic> and <bold>bold text</bold>
    </type1>
    <type2>
        Some text and <italic>italic Text</italic> and <bold>bold text</bold>
    </type2>
</bibliography>
<xsl:template match="/bibliography/*">
    <p>
        <div class="entry{@type}">
    [<xsl:number count="*"/>]
    <xsl:apply-templates/>
        </div>
    </p>
</xsl:template>
<xsl:template match="/">
    <div class="entry{@type}">
        <p>
            <fo:root>
                <fo:page-sequence>
                    <fo:flow>
                        <xsl:apply-templates select="bibliography"/>
                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </p>
    </div>
</xsl:template>
<xsl:template match="italic">
    <fo:inline font-style="italic">
        <xsl:apply-templates select="node()"/>
    </fo:inline>
</xsl:template>

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

部分文本、斜体文本和粗体文本
部分文本、斜体文本和粗体文本
此XSL可以工作,但没有
标记:

<xsl:template match="/bibliography/*">
    <p>
        <div class="entry{@type}">
    [<xsl:number count="*"/>]
    <xsl:apply-templates/>
        </div>
    </p>
</xsl:template>


[]

以下是我尝试在XML结构上使用解决方案的方式:

<bibliography>
    <type1>
        Some text and <italic>italic Text</italic> and <bold>bold text</bold>
    </type1>
    <type2>
        Some text and <italic>italic Text</italic> and <bold>bold text</bold>
    </type2>
</bibliography>
<xsl:template match="/bibliography/*">
    <p>
        <div class="entry{@type}">
    [<xsl:number count="*"/>]
    <xsl:apply-templates/>
        </div>
    </p>
</xsl:template>
<xsl:template match="/">
    <div class="entry{@type}">
        <p>
            <fo:root>
                <fo:page-sequence>
                    <fo:flow>
                        <xsl:apply-templates select="bibliography"/>
                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </p>
    </div>
</xsl:template>
<xsl:template match="italic">
    <fo:inline font-style="italic">
        <xsl:apply-templates select="node()"/>
    </fo:inline>
</xsl:template>

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


[]


除了XSL输出HTML和XSL-FO的混合外,它实际上似乎选择了“粗体”和“斜体”标记

如果您关注的是纯XSL-FO,那么看看您提到的问题,不需要做很多工作就可以让它与XML一起工作

<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 method="xml" indent="yes"/>

    <xsl:template match="bibliography">
        <fo:root>
            <fo:page-sequence>
                <fo:flow>
                    <xsl:apply-templates />
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="bibliography/*">
        <fo:block font-size="16pt" space-after="5mm">
            <xsl:apply-templates />
        </fo:block>
    </xsl:template>

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

    <xsl:template match="italic">
        <fo:inline font-style="italic">
            <xsl:apply-templates />
        </fo:inline>
    </xsl:template>
</xsl:stylesheet>


当然,它可能不起作用的一个原因可能是您的实际XML中有名称空间声明。在这种情况下,您也需要在XSLT中声明它,并相应地调整模板匹配。

我已经了解到XSL Fo只用于PDF,不用于HTML。这是否意味着没有将fo对象导出到HTML的选项?是否有另一种可能在没有XSL-FO的情况下添加
?XSL-FO通常用于输出HTML。如果要在浏览器中显示结果,只需修改它以输出HTML标记即可。我看到你问了另一个问题,我用这个答案的一个变体来回答。我希望有帮助。