XSLT 2.0 result-document
Added by Anonymous about 16 years ago
Legacy ID: #5676615 Legacy Poster: Lillian Sullam (lsullam)
Hi, I'm having some trouble with a very simple XSLT. I am using Saxon B 9.1.0.2 from my command line. Here is my command line prompt: java -classpath ....\saxon9.jar net.sf.saxon.Transform -o CreateFilesTest.xml comments.xml CreateFiles.xsl I have an output file for testing purposes, but ordinarily the XSLT file creates a directory for the output. Here is part of my input file: <?xml version='1.0' encoding='UTF-8'?> <book version="1.0" xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink"> <title>Reference Handbook</title> <info> <date>November 19, 2008</date> <abstract> <para/> </abstract> </info> <chapter xml:id="package-com.bruxton.sidx" xreflabel="com.bruxton.sidx"> <title>Package com.bruxton.sidx</title> <sect1 xml:id="class-com.bruxton.sidx.acquisition" xreflabel="com.bruxton.sidx.Acquisition"> <title>Class Acquisition</title> <indexterm><primary>Acquisition</primary></indexterm> Here is my complete XSLT: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" indent="yes"/> <xsl:template match="/"> <xsl:for-each select="book/chapter/sect1[contains(@xml:id,'')]"> <xsl:variable name="idx" select ="indexterm[1]/primary"></xsl:variable> <xsl:variable name="className" select ="substring-after(@xreflabel,'')"></xsl:variable> <xsl:variable name="filename" select="concat('Reference/',$idx,'.xml')"/> <xsl:result-document href="{$filename}" > <xsl:copy> <xsl:copy-of select="."/> </xsl:copy> </xsl:result-document> </xsl:for-each> </xsl:template> </xsl:stylesheet> It seems to work if I just copy over the entire document. But when I try to just copy each <sect1> nothing happens. Any help would be greatly appreciated! Thanks, Lillian
Replies (6)
Please register to reply
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5676797 Legacy Poster: Michael Kay (mhkay)
The output files are almost certainly being written, but not where you expect. Use the -t option on the command line to see where they are going. Any relative URI in the href attribute of result-document is interpreted relative to the "base output URI", which is set on the command line using the -o option, and defaults to the current directory.
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5676859 Legacy Poster: Lillian Sullam (lsullam)
I don't think that is happening. I have made a dummy input file: <?xml version="1.0" encoding="UTF-8"?> <book> <title>BookTest</title> <chapter> <title>ChapterTest</title> <sect1 xml:id="testsect1"> <title>Sect1Test</title> <indexterm> <primary>Testing1</primary> </indexterm> <para>some stuff</para> </sect1> <sect1 xml:id="testsect2"> <title>Sect2Test</title> <indexterm> <primary>Testing2</primary> </indexterm> <para>some stuff</para> </sect1> </chapter> </book> And the result is how I would expect. It goes to the correct folder. It seems there is something odd about the input file that I am trying to use. Or my XPath is off. Is there anything else that looks like it is wrong? I will try your suggestion, however I feel that my dummy file would have behaved the same way my intended input file if it was being sent to the wrong directory. Lillian
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5676949 Legacy Poster: Michael Kay (mhkay)
You're right, the problem has nothing to do with xsl:result-document. Your source document uses a default namespace but your path expression select="book/chapter/sect1[contains(@xml:id,'')]" is looking for elements in no namespace. Add xpath-default-namespace="http://docbook.org/ns/docbook" to the xsl:stylesheet element. Michael Kay http://www.saxonica.com/
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5677018 Legacy Poster: Lillian Sullam (lsullam)
Thank you! That worked perfectly!
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5677230 Legacy Poster: Lillian Sullam (lsullam)
I seem to be having the same problem with another stylesheet (XSLT 1.0 using saxon 6.5.5). I tried adding the xpath-default-namespace attribute but it said it was not allowed. Input file: <?xml version="1.0" encoding="UTF-8"?> <sect1 xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink"> <sect1 xml:id="class-com.bruxton.sidx.acquisition" xreflabel="com.bruxton.sidx.Acquisition"> <title>Class Acquisition</title> <indexterm> <primary>Acquisition</primary> </indexterm> <indexterm> <primary>Classes</primary> <secondary>Acquisition</secondary> </indexterm> <para>Responsible for managing the acquisition. Each instance of <literal> <link linkend="class-com.bruxton.sidx.camera">Camera</link> </literal> owns one instance of the class. The user of SIDX should not create the object. It should be obtained by using getAcquisition function of <literal> <link linkend="class-com.bruxton.sidx.camera">Camera</link> </literal> object.</para> <sect2> <title>Synopsis</title> <classsynopsis class="class" language="java"> XSLT 1.0 file: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" version="1.0" indent="yes"/> <!-- Class --> <xsl:template match="sect1/sect1[@]"> <xsl:call-template name="id_sect1"/> </xsl:template> <!-- Synopsis --> <xsl:template match="sect2"> <xsl:copy> <xsl:copy-of select="@"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> All that comes out is untagged text. Lillian
RE: XSLT 2.0 result-document - Added by Anonymous about 16 years ago
Legacy ID: #5677335 Legacy Poster: Michael Kay (mhkay)
This isn't really the right place to get XSLT coding help, now that we've established that you don't have a problem particular to Saxon. I would recommend the xsl-list at mulberrytech.com. The xpath-default-namespace attribute is an XSLT 2.0 feature. In XSLT 1.0 you have to bind a prefix to the namespace and use that prefix before every name appearing in a path expression or match pattern that refers to a name in that namespace.
Please register to reply