W3C home > Mailing lists > Public > xproc-dev@w3.org > June 2010

Re: Reading doctype-public and doctype-system from xsl:output

From: Romain Deltour <rdeltour@gmail.com>
Date: Mon, 14 Jun 2010 22:57:15 +0200
Message-Id: <8C1C824E-CF29-4BD3-947B-F6911874AC18@gmail.com>
To: xproc-dev@w3.org
Hi Jostein,

The p:validate-with-xml-schema step can only be used to validate  
against an XML Schema (see [1]). If you need to validate a document  
against a DTD you would have to use the p:load step (see [2]) with the  
@dtd-validate attribute. Note that if it will fail if the underlying  
XML parser is not a validating parser.

Also, note that the xsl:output element in you XSLT defines  
*serialization* options, which means that the XML infoset flowing  
through your pipeline won't retain this information (it doesn't matter  
if the XLST asks the output to be serialized with UTF8, or indented,  
etc).

Hope this helps,
Romain.

[1] http://www.w3.org/TR/xproc/#c.validate-with-xml-schema
[2] http://www.w3.org/TR/xproc/#c.load

Le 14 juin 10 à 16:03, Jostein Austvik Jacobsen a écrit :

> Hi.
>
> How can I use the DTD defined in the doctype, where the doctype is  
> defined in a xsl:output in a p:xslt step, to validate and p:store  
> the resulting XML? Here's some code to demonstrate my problem:
>
> ---- begin input.xml ----
> <?xml version="1.0" encoding="windows-1252"?>
> <!DOCTYPE document SYSTEM "http://www.idunn.no/dtd/document1.5_Idunn.dtd 
> ">
> <document>
>       <metaData>
>             <title>Hello XProc!</title>
>             <logicalTitle>ht-2009-4-1</logicalTitle>
>             <description/>
>             <language>no_NO</language>
>             <commenting>off</commenting>
>             <indexing>on</indexing>
>             <subject/>
>             <categoryPrimary/>
>             <author>
>                   <firstName/>
>                   <lastName/>
>             </author>
>             <contentType>content_document_editorial</contentType>
>             <colleague>false</colleague>
>       </metaData>
>       <contributors/>
>       <contentSection>
>             <para>Hello XProc!</para>
>       </contentSection>
> </document>
> ---- end input.xml ----
>
>
> ---- begin transform.xsl ----
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> version="2..0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/2009/mf 
> " exclude-result-prefixes="xs mf" xmlns="http://www.daisy.org/z3986/2005/dtbook/ 
> ">
>
>     <!--
>         Here I specify the doctype, and I would assume that it  
> carried through to the XProc script, however that seems not to be  
> the case.
>     -->
>     <xsl:output method="xml" version="1.0" doctype-public="-//NISO// 
> DTD dtbook 2005-2//EN" doctype-system="http://www.daisy.org/z3986/2005/dtbook-2005-2.dtd 
> " encoding="utf-8"/>
>
>     <xsl:template match="document">
>         <dtbook xmlns="http://www.daisy.org/z3986/2005/dtbook/"  
> version="2005-2" xml:lang="no">
>             <head/>
>             <book showin="blp">
>                 <xsl:apply-templates select="contentSection"/>
>             </book>
>         </dtbook>
>     </xsl:template>
>     <xsl:template match="contentSection">
>         <bodymatter>
>             <level1>
>                 <h1><xsl:value-of select="/document/metaData[1]/ 
> title[1]"></xsl:value-of></h1>
>                 <xsl:apply-templates/>
>             </level1>
>         </bodymatter>
>     </xsl:template>
>     <xsl:template match="para">
>         <p><xsl:apply-templates/></p>
>     </xsl:template>
> </xsl:stylesheet>
>
> ---- end transform.xsl ----
>
>
> ---- begin pipe.xpl ----
> <?xml version="1.0" encoding="UTF-8"?>
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step 
> " version="1.0">
>
>     <p:input port="source" primary="true">
>         <p:document href="input.xml"/>
>     </p:input>
>
>     <p:xslt version="1.0">
>         <p:input port="parameters">
>             <p:empty/>
>         </p:input>
>         <p:input port="stylesheet">
>             <p:document href="transform.xsl"></p:document>
>         </p:input>
>     </p:xslt>
>
>     <!--  How would I validate the XML here? I would prefer to use  
> the DTD specified
>         in the output from the XSLT transformation instead of  
> explicitly setting
>         a URL to it: -->
>     <!-- <p:validate-with-xml-schema/> -->
>
>     <p:store href="dtbook.xml">
>         <!--
>             If I don't specify the doctype as options here, then the  
> resulting
>             document doesn't get a <!DOCTYPE ...>. I would like to  
> pass through
>             the doctype from the XSLT-transformation here.
>         -->
>         <p:with-option name="encoding" select="'UTF-8'"/>
>         <p:with-option name="doctype-public" select="'-//NISO//DTD  
> dtbook 2005-2//EN'"/>
>         <p:with-option name="doctype-system" select="'http://www.daisy.org/z3986/2005/dtbook-2005-2.dtd' 
> "/>
>     </p:store>
>
> </p:declare-step>
> ---- end pipe.xpl ----
>
>
> ---- begin dtbook.xml ----
> <!DOCTYPE dtbook PUBLIC "-//NISO//DTD dtbook 2005-2//EN" "http://www.daisy.org/z3986/2005/dtbook-2005-2.dtd 
> ">
> <dtbook xmlns="http://www.daisy.org/z3986/2005/dtbook/"  
> version="2005-2" xml:lang="no">
>   <head/>
>   <book showin="blp">
>     <bodymatter>
>       <level1>
>         <h1>Hello XProc!</h1>
>         <p>Hello XProc!</p>
>       </level1>
>     </bodymatter>
>   </book>
> </dtbook>
> ---- end dtbook.xml ----
>
>
> The pipe.xpl-script takes input.xml as input, applies transform.xsl  
> on it and stores the result as dtbook.xml. The code, as shown,  
> should be all valid and run without errors, resulting in dtbook.xml  
> (see comments in the code.) I'm using oXygen/Calabash.
>
>
> Best regards
> Jostein Austvik Jacobsen
Received on Monday, 14 June 2010 20:57:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 14 June 2010 20:57:56 GMT