Xslt 到 xsl-fo 转换 [英] Xslt to xsl-fo transformation
问题描述
我想将 xslt 转换为 xsl-fo,但我不确定我能做到这一点.我尝试将 XML 列表转换为 xsl-fo 列表.谁能告诉我在哪里可以找到我在谷歌上搜索了很长时间,没有很多这样的例子.我的 XML 是这样的.
I want make a xslt transformation to xsl-fo but I´m not really sure that I can do this. I try to convert a XML list to a xsl-fo list. Can anyone tell me where can i look for I´m googling for a long time are there aren´t a lot of examples of this. My XML is like this.
<p>TEXT</p>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
<p>ANOTHERTEXT</p>
我尝试使用模板进行此转换,但我的模板无法获得 xsl-fo 谁能告诉我模板是否适用于此转换.如果他们的工作可以向我展示一个例子,我找不到任何人.我的目标是得到一个 pdf whit fop
I try use templates for this transformation but my templates don't work to get xsl-fo Can anybody tell me if the templates work in this transformation. If they work can show me an example i can't find anyone. My objetive is get a pdf whit fop
谢谢
这是我的 XML 文档的一部分,我收到了 HTML 中源代码的某些部分,现在我将 HTML 更改为 XML 我尝试将 XML(带有列表)转换为带有 XSLT 的 XSL-FO.我的问题是我无法将模板应用于这种转换.我的最终目标是获得带有 FOP 的 pdf.
This is part of my XML document I recived some parts of the source in HTML and I change HTML to XML now I try convert XML (whit a list) into XSL-FO whit a XSLT. My problem is that I can´t aply templates to this transformation. My final objetive is get a pdf whit FOP.
谢谢
更新
这是我的 XML:
<Memoria>
<name>TITLE</name>
<Index>INDEX 2010</Index>
<Seccion>
<name>INFORMATION</name>
<Contenido>
<p>TEXT</p>
<ul>
<li>ITEM1</li>
<li>ITEM2</li>
</ul>
<p>ANOTHER</p>
</Contenido>
</Seccion>
</Memoria>
我正在测试您的解决方案 谢谢大家
I'm testing your solution Thanks all
推荐答案
如果您的模板无法正常工作,则可能是命名空间问题.您应该使用更准确的 XML 示例更新问题.
If you're having issues with your templates not working, it might be a namespace issue. You should update the question with a more accurate example of your XML.
这是一个例子.
XML Input(固定为格式良好)
<root>
<p>TEXT</p>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
<p>ANOTHERTEXT</p>
</root>
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:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
<fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="p">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="ul">
<fo:list-block padding="4pt">
<xsl:apply-templates/>
</fo:list-block>
</xsl:template>
<xsl:template match="li">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
</xsl:stylesheet>
XSL-FO 输出
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
<fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>TEXT</fo:block>
<fo:list-block padding="4pt">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>Item1</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>Item2</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block>ANOTHERTEXT</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Apache FOP 输出
这篇关于Xslt 到 xsl-fo 转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!