Example: hello.xml
<?xml version="1.0" encoding="UTF-8"?>
<article version="5.0">
<info>
<title>Sample</title>
</info>
<para>Hello World</para>
</article>
XSL ファイルを作成Example: pdf.xsl
<?xml version="1.0" encoding="utf-8"?>
<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 encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<fo:region-body margin="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates/>
</fo:root>
</xsl:template>
<xsl:template match="/article">
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="./info/title"/>
<xsl:apply-templates select=".//para"/>
</fo:flow>
</fo:page-sequence>
</xsl:template>
<xsl:template match="//info/title">
<fo:block font-size="20pt"><xsl:apply-templates/></fo:block>
</xsl:template>
<xsl:template match="//para">
<fo:block font-size="10.5pt"><xsl:apply-templates/></fo:block>
</xsl:template>
</xsl:stylesheet>
Table: FOP コマンドのオプション
| 引数 | 意味 |
|---|---|
| -fo infile | xsl:fo input file |
| -xml infile | xml input file, -xsl と一緒に使用すること |
| -xsl stylesheet | xslt stylesheet |
| -awt | 出力結果をディスプレイに表示 |
| -pdf outfile | PDF ファイルを生成 |
| -foout outfile | XSL-FO ファイルを生成する |
PDF に変換する
>..\fop-0.95\fop.bat -xsl pdf.xsl -xml sample_pdf.xml -pdf sample.pdf
XML, XSL から FO ファイルを生成
>..\fop-0.95\fop.bat -xsl pdf.xsl -xml sample_pdf.xml -pdf -foout sample.fo生成された FO ファイル
<?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="A4"> <fo:region-body margin="2cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="A4"> <fo:flow flow-name="xsl-region-body"> <fo:block font-size="10.5pt">Hello World</fo:block> </fo:flow> </fo:page-sequence> </fo:root>
0 件のコメント:
コメントを投稿