# yum install saxon
動作確認
Example: test.xml
<?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet href="test.xsl" type="text/xsl" ?> <document> <header>はじめての XML, XSLT</header> <paragraph>XML ,XSLT テスト</paragraph> </document>
Example: test.xsl
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="document"> <html><xsl:apply-templates/></html> </xsl:template> <xsl:template match="header"> <h1><xsl:value-of select="."/></h1> </xsl:template> <xsl:template match="paragraph"> <p><xsl:value-of select="."/></p> </xsl:template> </xsl:stylesheet>saxon.jar を使って test.html を生成
$ java -jar /usr/share/java/saxon.jar -s:test.xml -xsl:test.xsl -o:test.html Warning: at xsl:stylesheet on line 2 column 81 of test.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
DocBook で使う
DocBook の Style Sheet は /usr/share/sgml/docbook/xsl-stylesheets/xhtml/docbook.xsl にインストールされている
Example: test.xsl
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "/usr/share/sgml/docbook/xml-dtd-4.5/docbookx.dtd"> <article> <title>Hello, world</title> <sect1> <title>Hello, world</title> <para>Hello, world</para> <sect2> <title>こんにちは</title> <para>日本語表示できますか?</para> </sect2> </sect1> </article>
$ java -jar /usr/share/java/saxon.jar -s:hello.xml -xsl:/usr/share/sgml/docbook/xsl-stylesheets/xhtml/docbook.xsl -o:hello.html Warning: at xsl:stylesheet on line 4 column 317 of docbook.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
Ant (build.xml)
src ディレクトリにある原稿 xml を SAXON を通して DocBook の HTML ファイルを生成する build.xml は以下の通り。
<?xml version="1.0" encoding="UTF-8"?> <project name="saxonTest" basedir="." default="html"> <property name="BUILD" location="build"/> <property name="SRC" location="src"/> <property name="DOCBOOK_PUBLIC_ID" value="-//OASIS//DTD DocBook XML V4.5//EN"/> <property name="DOCBOOK_DTD" value="/usr/share/sgml/docbook/xml-dtd-4.5/docbookx.dtd"/> <property name="DOCBOOK_XSL" location="/usr/share/sgml/docbook/xsl-stylesheets/xhtml/docbook.xsl"/> <property name="SAXON_LOC" location="/usr/share/java/saxon.jar"/> <target name="init"> <tstamp/> <mkdir dir="${BUILD}"/> </target> <target name="html" depends="init"> <xmlvalidate warn="false"> <xmlcatalog> <dtd publicId="${DOCBOOK_PUBLIC_ID}" location="${DOCBOOK_DTD}"/> </xmlcatalog> <fileset dir="${SRC}"> <include name="*.xml"/> </fileset> </xmlvalidate> <xslt basedir="${SRC}" destdir="${BUILD}" style="${DOCBOOK_XSL}" extension=".html" includes="*.xml"> <classpath> <pathelement location="${SAXON_LOC}"/> </classpath> <factory name="net.sf.saxon.TransformerFactoryImpl"/> <xmlcatalog> <dtd publicId="${DOCBOOK_PUBLIC_ID}" location="${DOCBOOK_DTD}"/> </xmlcatalog> </xslt> </target> <target name="clean"> <delete dir="${BUILD}"/> </target> </project><xslt> の中で <factory name="net.sf.saxon.TransformerFactoryImpl"/> を指定していないと TraXLiaison を使用してエラーとなる。明示的に SAXON を使うために factory name で指定しておくこと。
$ ant -verbose Apache Ant(TM) version 1.8.2 compiled on February 10 2011 Trying the default build file: build.xml Buildfile: /home/user/Develop/docbook/saxonTest/antTest/build.xml (略) [xmlvalidate] 2 file(s) have been successfully validated. [xslt] Using class org.apache.tools.ant.taskdefs.optional.TraXLiaison [xslt] Transforming into /home/user/Develop/docbook/saxonTest/antTest/build [xslt] Processing /home/user/Develop/docbook/saxonTest/antTest/src/hello.xml to /home/user/Develop/docbook/saxonTest/antTest/build/hello.html [xslt] Loading stylesheet /usr/share/sgml/docbook/xsl-stylesheets/xhtml/docbook.xsl Apache resolver library not found, internal resolver will be used [xslt] : Warning! file:/usr/share/sgml/docbook/xsl-stylesheets/xhtml/autoidx.xsl: line 502: 属性 'href' がエレメントの外側です。 (略) [xslt] : Error! null [xslt] Failed to process null BUILD FAILED
0 件のコメント:
コメントを投稿