xslt到fo的转换:生成格式不同的数字标题
我尝试使用XSLT将XML结构转换为FO脚本。我有编号标题的问题。 我的XML结构如下所示:xslt到fo的转换:生成格式不同的数字标题,xslt,numbers,xsl-fo,heading,Xslt,Numbers,Xsl Fo,Heading,我尝试使用XSLT将XML结构转换为FO脚本。我有编号标题的问题。 我的XML结构如下所示: <?xml version="1.0"?> <document> <type1> <heading>Topic level1</heading> <paragraph>Text</paragraph> </type1> <type2> <
<?xml version="1.0"?>
<document>
<type1>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type1>
<type2>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type2>
<type1>
<heading>Topic level1</heading>
<type1>
<heading>Topic level2</heading>
<paragraph>Text</paragraph>
</type1>
<heading>Topic level3</heading>
<paragraph>Text</paragraph>
</type1>
</type1>
</type1>
...
</document>
<xsl:template match="type1/heading | type2/heading | type3/heading | type4/heading |
type5/heading | type6/heading | type7/heading">
<fo:block font-weight="bold" font-size="13pt" space-after="5mm" id="{generate-
Id()}">
<xsl:number count="type1| type2| type3| type4| type5| type6 | type7"
format="1.1" level="multiple"/> 
<xsl:apply-templates/>
</fo:block>
</xsl:template>
主题级别1
正文
主题级别1
正文
主题级别1
主题级别2
正文
主题级别3
正文
...
原始XML结构嵌套更深,包含更多元素。
现在我有一个这样的模板:
<?xml version="1.0"?>
<document>
<type1>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type1>
<type2>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type2>
<type1>
<heading>Topic level1</heading>
<type1>
<heading>Topic level2</heading>
<paragraph>Text</paragraph>
</type1>
<heading>Topic level3</heading>
<paragraph>Text</paragraph>
</type1>
</type1>
</type1>
...
</document>
<xsl:template match="type1/heading | type2/heading | type3/heading | type4/heading |
type5/heading | type6/heading | type7/heading">
<fo:block font-weight="bold" font-size="13pt" space-after="5mm" id="{generate-
Id()}">
<xsl:number count="type1| type2| type3| type4| type5| type6 | type7"
format="1.1" level="multiple"/> 
<xsl:apply-templates/>
</fo:block>
</xsl:template>
输出基本正常。但所有标题都有相同的样式参数。我想有不同的风格为不同的标题水平。
例如:
<?xml version="1.0"?>
<document>
<type1>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type1>
<type2>
<heading>Topic level1</heading>
<paragraph>Text</paragraph>
</type2>
<type1>
<heading>Topic level1</heading>
<type1>
<heading>Topic level2</heading>
<paragraph>Text</paragraph>
</type1>
<heading>Topic level3</heading>
<paragraph>Text</paragraph>
</type1>
</type1>
</type1>
...
</document>
<xsl:template match="type1/heading | type2/heading | type3/heading | type4/heading |
type5/heading | type6/heading | type7/heading">
<fo:block font-weight="bold" font-size="13pt" space-after="5mm" id="{generate-
Id()}">
<xsl:number count="type1| type2| type3| type4| type5| type6 | type7"
format="1.1" level="multiple"/> 
<xsl:apply-templates/>
</fo:block>
</xsl:template>
1.主题级别1
正文
2.主题级别1
正文
3.主题级别1
正文
3.1主题级别2
正文
3.1.1主题级别3
正文
我该怎么做呢?您可以通过计算
结果中的点数或type1 | type2的祖先数等来确定当前标题的级别。您可以(a)将输入示例修改为格式良好的XML,以及(b)将预期结果作为代码发布吗?有很多方法可以实现您的愿望,但是您需要显示更多的模板,特别是它们后面的模板或“type”元素中的其他模板。您可以在匹配中为每个“type”元素应用样式,并让标题继承该样式。