[英]format italic/bold tag with xpath and/or xsl-fo
我有类似这样的问题: 使用XSLT创建带有嵌套的粗体/斜体标签的XSL-FO 。 我想检测XML文本中的<italic>
和<bold>
标记,并将其正确地显示为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有效,但没有<italic>
或<bold>
标记:
<xsl:template match="/bibliography/*">
<p>
<div class="entry{@type}">
[<xsl:number count="*"/>]
<xsl:apply-templates/>
</div>
</p>
</xsl:template>
这就是我尝试在XML结构上使用解决方案的方式:
<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的混合内容外,它实际上似乎还带有“ bold”和“ italic”标签。
如果您追求纯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中声明它,并相应地调整模板匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.