--- /dev/null
+ <!ENTITY components-extra ""> <!-- for customisation -->
+ <!ENTITY components "dbk:appendix |
+ dbk:article |
+ dbk:book |
+ dbk:chapter |
+ dbk:part |
+ dbk:preface |
+ dbk:section |
+ dbk:sect1 |
+ dbk:sect2 |
+ dbk:sect3 |
+ dbk:sect4 |
+ dbk:sect5
+ &components-extra;">
+
+ <!ENTITY blocks-extra ""> <!-- for customisation -->
+ <!ENTITY blocks "dbk:bibliography |
+ dbk:bibliodiv |
+ dbk:glossary |
+ dbk:glossdiv |
+ dbk:qandaset |
+ dbk:qandadiv
+ &blocks-extra;">
+
+ <!ENTITY metadata-extra ""> <!-- for customisation -->
+ <!ENTITY metadata-content 'contains(@rnd:style, "-title") or
+ contains(@rnd:style, "-subtitle") or
+ @rnd:style = "abstract" or
+ @rnd:style = "author" or
+ @rnd:style = "editor" or
+ @rnd:style = "publisher" or
+ @rnd:style = "publisher-address" or
+ @rnd:style = "othercredit" or
+ @rnd:style = "revhistory" or
+ @rnd:style = "revision" or
+ @rnd:style = "date" or
+ @rnd:style = "pubdate" or
+ @rnd:style = "personblurb" or
+ @rnd:style = "address" or
+ @rnd:style = "affiliation" or
+ @rnd:style = "contrib" or
+ @rnd:style = "email" or
+ @rnd:style = "pagenums" or
+ @rnd:style = "issuenum" or
+ @rnd:style = "volumenum" or
+ @rnd:style = "biblioid" or
+ @rnd:style = "bibliosource" or
+ @rnd:style = "bibliomisc" or
+ @rnd:style = "releaseinfo"
+ &metadata-extra;'>
+
+ <!ENTITY author-extra ""> <!-- for customisation -->
+ <!ENTITY author-content '@rnd:style = "author" or
+ @rnd:style = "personblurb" or
+ @rnd:style = "address" or
+ @rnd:style = "affiliation" or
+ @rnd:style = "contrib" or
+ @rnd:style = "email"
+ &author-extra;'>
+
+ <!ENTITY admonition-extra ""> <!-- for customisation -->
+ <!ENTITY admonition '@rnd:style = "caution" or
+ @rnd:style = "important" or
+ @rnd:style = "note" or
+ @rnd:style = "tip" or
+ @rnd:style = "warning"
+ &admonition-extra;'>
+ <!ENTITY admonition-title-extra ""> <!-- for customisation -->
+ <!ENTITY admonition-title '@rnd:style = "caution-title" or
+ @rnd:style = "important-title" or
+ @rnd:style = "note-title" or
+ @rnd:style = "tip-title" or
+ @rnd:style = "warning-title"
+ &admonition-title-extra;'>
-<!DOCTYPE xsl:stylesheet [
- <!ENTITY components "dbk:appendix |
- dbk:article |
- dbk:book |
- dbk:chapter |
- dbk:part |
- dbk:preface |
- dbk:section |
- dbk:sect1 |
- dbk:sect2 |
- dbk:sect3 |
- dbk:sect4 |
- dbk:sect5">
-
- <!ENTITY blocks "dbk:bibliography |
- dbk:bibliodiv |
- dbk:glossary |
- dbk:glossdiv |
- dbk:qandaset |
- dbk:qandadiv">
-
- <!ENTITY metadata-content '@rnd:style = "abstract" or
- @rnd:style = "abstract-title" or
- @rnd:style = "author" or
- @rnd:style = "editor" or
- @rnd:style = "othercredit" or
- @rnd:style = "revhistory" or
- @rnd:style = "revision" or
- @rnd:style = "date" or
- @rnd:style = "pubdate" or
- @rnd:style = "personblurb" or
- @rnd:style = "address" or
- @rnd:style = "affiliation" or
- @rnd:style = "contrib" or
- @rnd:style = "email" or
- @rnd:style = "pagenums" or
- @rnd:style = "issuenum" or
- @rnd:style = "volumenum" or
- @rnd:style = "biblioid" or
- @rnd:style = "bibliosource" or
- @rnd:style = "releaseinfo"'>
-
- <!ENTITY author-content '@rnd:style = "author" or
- @rnd:style = "personblurb" or
- @rnd:style = "address" or
- @rnd:style = "affiliation" or
- @rnd:style = "contrib" or
- @rnd:style = "email"'>
-
- <!ENTITY admonition '@rnd:style = "caution" or
- @rnd:style = "important" or
- @rnd:style = "note" or
- @rnd:style = "tip" or
- @rnd:style = "warning"'>
- <!ENTITY admonition-title '@rnd:style = "caution-title" or
- @rnd:style = "important-title" or
- @rnd:style = "note-title" or
- @rnd:style = "tip-title" or
- @rnd:style = "warning-title"'>
-]>
+<!DOCTYPE xsl:stylesheet SYSTEM "blocks2dbk.dtd">
+<!-- External DTD defines entities:
+ components :- QNames of component-level elements
+ blocks :- QNames of block-level elements
+ metadata-content :- XPath expression matching metadata styles
+ author-content :- XPath expression matching author styles
+ admonition :- XPath expression matching admonition styles
+ admonition-title :- XPath expression matching admonition title styles
+-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dbk='http://docbook.org/ns/docbook'
<xsl:apply-templates/>
</dbk:bibliomixed>
</xsl:when>
- <xsl:when test='@rnd:style = "biblioentry"'>
- <!-- TODO: handle titles, metadata, etc -->
+ <xsl:when test='@rnd:style = "biblioentry-title"'>
<dbk:biblioentry>
- <xsl:apply-templates/>
+ <dbk:title>
+ <xsl:apply-templates/>
+ </dbk:title>
+ <xsl:if test='following-sibling::*[1][&metadata-content;]'>
+ <xsl:apply-templates select='following-sibling::*[1]'
+ mode='rnd:metadata'/>
+ </xsl:if>
</dbk:biblioentry>
</xsl:when>
</xsl:when>
<xsl:when test='@rnd:style = "bridgehead"'>
- <xsl:element name='{@rnd:style}'>
+ <xsl:element name='{@rnd:style}'
+ namespace='http://docbook.org/ns/docbook'>
<xsl:call-template name='rnd:attributes'/>
<xsl:apply-templates/>
</xsl:element>
</xsl:call-template>
</xsl:when>
+ <xsl:when test='@rnd:style = "informalfigure-imagedata"'>
+ <dbk:informalfigure>
+ <dbk:mediaobject>
+ <dbk:imageobject>
+ <dbk:imagedata fileref='{.}'/>
+ </dbk:imageobject>
+ </dbk:mediaobject>
+ </dbk:informalfigure>
+ </xsl:when>
+
<xsl:when test='(contains(@rnd:style, "-title") or
contains(@rnd:style, "-titleabbrev") or
contains(@rnd:style, "-subtitle")) and
<xsl:when test='@rnd:style = preceding-sibling::node()[self::dbk:emphasis]/@rnd:style'/>
- <xsl:when test='@rnd:style = "citetitle"'>
- <xsl:element name='{@rnd:style}'>
+ <xsl:when test='@rnd:style = "citetitle" or
+ @rnd:style = "literal" or
+ @rnd:style = "sgmltag"'>
+ <xsl:element name='{@rnd:style}'
+ namespace='http://docbook.org/ns/docbook'>
<xsl:call-template name='rnd:attributes'/>
<xsl:apply-templates/>
<xsl:apply-templates select='following-sibling::node()[1]'
<xsl:template match='dbk:para' mode='rnd:metadata'>
<xsl:choose>
+ <xsl:when test='@rnd:style = "biblioentry-title"'>
+ <xsl:call-template name='rnd:error'>
+ <xsl:with-param name='code'>bad-metadata</xsl:with-param>
+ <xsl:with-param name='message'>style "<xsl:value-of select='@rnd:style'/>" must not be metadata for parent "<xsl:value-of select='local-name(..)'/>"</xsl:with-param>
+ </xsl:call-template>
+ </xsl:when>
<xsl:when test='@rnd:style = "abstract-title" or
@rnd:style = "abstract"'>
<xsl:variable name='stop.node'
@rnd:style = "othercredit" or
@rnd:style = "biblioid" or
@rnd:style = "bibliosource" or
+ @rnd:style = "bibliomisc" or
@rnd:style = "revhistory" or
@rnd:style = "revision"'>
<xsl:element name='{@rnd:style}'
<xsl:apply-templates select='following-sibling::*[1]'
mode='rnd:metadata'/>
</xsl:when>
+
+ <!-- Exception to normal subtitle handling is biblioentry-subtitle -->
+ <xsl:when test='@rnd:style = "biblioentry-subtitle"'>
+ <!-- TODO: check that this is in a biblioentry -->
+ <dbk:subtitle>
+ <xsl:apply-templates mode='rnd:metadata'/>
+ </dbk:subtitle>
+
+ <xsl:apply-templates select='following-sibling::*[1]'
+ mode='rnd:metadata'/>
+ </xsl:when>
<xsl:when test='contains(@rnd:style, "-subtitle")'>
<xsl:variable name='parent'
select='substring-before(@rnd:style, "-subtitle")'/>
<xsl:apply-templates select='following-sibling::*[1]'
mode='rnd:metadata'/>
</xsl:when>
+
+ <xsl:when test='@rnd:style = "publisher-address"'>
+ <xsl:apply-templates select='following-sibling::*[1]'
+ mode='rnd:metadata'/>
+ </xsl:when>
+ <xsl:when test='@rnd:style = "publisher"'>
+ <dbk:publisher>
+ <dbk:publishername>
+ <xsl:apply-templates/>
+ </dbk:publishername>
+ <xsl:if test='following-sibling::*[1][@rnd:style = "publisher-address"]'>
+ <xsl:apply-templates select='following-sibling::*[1]'
+ mode='rnd:publisher'/>
+ </xsl:if>
+ </dbk:publisher>
+
+ <xsl:apply-templates select='following-sibling::*[1]'
+ mode='rnd:metadata'/>
+ </xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match='dbk:emphasis' mode='rnd:metadata'>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
- <xsl:element name='{@rnd:style}'>
+ <xsl:element name='{@rnd:style}'
+ namespace='http://docbook.org/ns/docbook'>
<xsl:apply-templates mode='rnd:metadata'/>
</xsl:element>
</xsl:otherwise>
</xsl:if>
</xsl:template>
+ <xsl:template match='dbk:para' mode='rnd:publisher'>
+ <xsl:if test='@rnd:style = "publisher-address"'>
+ <dbk:address>
+ <xsl:apply-templates/>
+ </dbk:address>
+ </xsl:if>
+ </xsl:template>
+
<xsl:template match='dbk:para' mode='rnd:programlisting'>
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
--- /dev/null
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+
+ xmlns:sfa="http://developer.apple.com/namespaces/sfa"
+ xmlns:sf="http://developer.apple.com/namespaces/sf"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:appsl="http://developer.apple.com/namespaces/sl"
+
+ xmlns:dbk='http://docbook.org/ns/docbook'
+ xmlns:rnd='http://docbook.org/ns/docbook/roundtrip'
+ exclude-result-prefixes='sfa sf xsi appsl'>
+
+ <xsl:output method="xml" indent='yes'/>
+
+ <!-- ********************************************************************
+ $Id$
+ ********************************************************************
+
+ This file is part of the XSL DocBook Stylesheet distribution.
+ See ../README or http://nwalsh.com/docbook/xsl/ for copyright
+ and other information.
+
+ ******************************************************************** -->
+
+ <xsl:strip-space elements='*'/>
+ <xsl:preserve-space elements='sf:span'/>
+
+ <xsl:key name='styles'
+ match='sf:paragraphstyle[not(ancestor::appsl:section-prototypes)] |
+ sf:characterstyle[not(ancestor::appsl:section-prototypes)] |
+ sf:table-style'
+ use='@sf:ident|@sfa:ID'/>
+
+ <xsl:key name='ids'
+ match='*'
+ use='@sfa:ID'/>
+
+ <xsl:template match='appsl:document'>
+ <dbk:article>
+ <!-- TODO: headers and footers -->
+ <xsl:apply-templates select='sf:text-storage'/>
+ </dbk:article>
+ </xsl:template>
+
+ <xsl:template match='sf:p'>
+ <xsl:choose>
+ <xsl:when test='sf:attachment-ref and
+ count(*) = count(sf:attachment-ref|sf:br)'>
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <dbk:para>
+ <xsl:variable name='style-name'>
+ <xsl:call-template name='rnd:find-style'/>
+ </xsl:variable>
+ <xsl:if test='$style-name != "" and
+ $style-name != "para"'>
+ <xsl:attribute name='rnd:style'>
+ <xsl:value-of select='$style-name'/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:apply-templates/>
+ </dbk:para>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match='sf:span'>
+ <xsl:variable name='style-name'
+ select='key("styles", @sf:style)/self::sf:characterstyle/@sf:name'/>
+
+ <xsl:variable name='char-style'>
+ <xsl:call-template name='rnd:find-style'>
+ <xsl:with-param name='char-style-name' select='$style-name'/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test='$style-name = "attribute-name"'>
+ <xsl:if test='not(preceding-sibling::node()[not(self::text()) or (self::text() and normalize-space() != "")])'>
+ <xsl:attribute name='{.}'>
+ <xsl:apply-templates select='following-sibling::*[1][self::sf:span]'
+ mode='attribute'/>
+ </xsl:attribute>
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test='$style-name = "attribute-value"'/>
+ <xsl:when test='$style-name = ""'>
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:when test='$char-style = "superscript" or
+ $char-style = "subscript"'>
+ <xsl:element name='{$char-style}'
+ namespace='http://docbook.org/ns/docbook'>
+ <xsl:apply-templates/>
+ </xsl:element>
+ </xsl:when>
+ <xsl:otherwise>
+ <dbk:emphasis>
+ <xsl:choose>
+ <xsl:when test='$char-style = "emphasis-bold" or
+ $char-style = "emphasis-strong"'>
+ <xsl:attribute name='role'>bold</xsl:attribute>
+ </xsl:when>
+ <xsl:when test='$char-style != "" and
+ $char-style != "emphasis"'>
+ <xsl:attribute name='rnd:style'>
+ <xsl:value-of select='$char-style'/>
+ </xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+
+ <xsl:apply-templates/>
+ </dbk:emphasis>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match='*' mode='attribute'>
+ <xsl:variable name='style-name'
+ select='key("styles", @sf:style)/self::sf:characterstyle/@sf:name'/>
+
+ <xsl:if test='$style-name = "attribute-value"'>
+ <xsl:apply-templates/>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match='sf:br'/>
+ <xsl:template match='sf:lnbr|sf:crbr'>
+ <xsl:text>
</xsl:text>
+ </xsl:template>
+ <xsl:template match='sf:tab'>
+ <xsl:text> </xsl:text>
+ </xsl:template>
+ <xsl:template match='sf:link'>
+ <dbk:ulink url='{@href}'>
+ <xsl:apply-templates/>
+ </dbk:ulink>
+ </xsl:template>
+
+ <xsl:template match='sf:attachment-ref'>
+ <xsl:if test='@sf:kind = "table-attachment"'>
+ <xsl:apply-templates select='key("ids", @sfa:IDREF)'/>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match='sf:attachment[@sf:kind = "table-attachment"]'>
+ <!-- Assumes: (1) table has a header row, (2) cell style is not redefined, (3) no column spans -->
+ <xsl:variable name='hdr-cells'
+ select='.//sf:table-cell[key("ids", sf:tableCellStyle-ref/@sfa:IDREF)/@sf:parent-ident = "table-header-row-cell-style-default"]'/>
+
+ <xsl:variable name='num-cols' select='count($hdr-cells)'/>
+
+ <!-- This is unreliable... must account for row/column spans -->
+ <xsl:variable name='num-rows'
+ select='floor(count(sf:tableAttachmentTable/sf:tableModelCells/sf:tableCellArrayCellsByRow/sf:table-cell) div $num-cols)'/>
+
+ <xsl:choose>
+ <xsl:when test='not($num-rows) or $num-rows = ""'>
+ <xsl:message> cannot determine num-rows </xsl:message>
+ <xsl:comment> cannot determine num-rows </xsl:comment>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <!-- TODO: borders, column widths -->
+ <dbk:informaltable>
+ <dbk:tgroup cols='{$num-cols}'>
+ <xsl:call-template name='rnd:make-colspecs'>
+ <xsl:with-param name='num-cols' select='$num-cols'/>
+ </xsl:call-template>
+ <dbk:tbody>
+ <xsl:apply-templates/>
+ </dbk:tbody>
+ </dbk:tgroup>
+ </dbk:informaltable>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template name='rnd:make-colspecs'>
+ <xsl:param name='num-cols' select='0'/>
+
+ <xsl:choose>
+ <xsl:when test='$num-cols <= 0 or
+ $num-cols = ""'/>
+ <xsl:otherwise>
+ <dbk:colspec/>
+ <xsl:call-template name='rnd:make-colspecs'>
+ <xsl:with-param name='num-cols' select='$num-cols - 1'/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match='sf:tableCellArrayCellsByRow'>
+ <xsl:variable name='hdr-cells'
+ select='sf:table-cell[key("ids", sf:tableCellStyle-ref/@sfa:IDREF)/@sf:parent-ident = "table-header-row-cell-style-default"]'/>
+
+ <xsl:variable name='num-cols' select='count($hdr-cells)'/>
+
+ <xsl:variable name='num-rows'
+ select='floor(count(sf:table-cell) div $num-cols)'/>
+
+ <xsl:call-template name='rnd:table-rows'>
+ <xsl:with-param name='num-cols' select='$num-cols'/>
+ <xsl:with-param name='cells' select='sf:table-cell'/>
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name='rnd:table-rows'>
+ <xsl:param name='num-cols' select='0'/>
+ <xsl:param name='cells' select='/..'/>
+
+ <xsl:choose>
+ <xsl:when test='count($cells) = 0'/>
+ <xsl:otherwise>
+ <dbk:row>
+ <xsl:apply-templates select='$cells[position() <= $num-cols]'/>
+ </dbk:row>
+ <xsl:call-template name='rnd:table-rows'>
+ <xsl:with-param name='num-cols'
+ select='$num-cols'/>
+ <xsl:with-param name='cells'
+ select='$cells[position() > $num-cols]'/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <xsl:template match='sf:table-cell'>
+ <dbk:entry>
+ <xsl:apply-templates select='sf:tableCellContent/sf:text-storage/sf:text-body/sf:layout'/>
+ </dbk:entry>
+ </xsl:template>
+ <xsl:template match='sf:tableAttachmentTable |
+ sf:tableModelCells'>
+ <xsl:apply-templates/>
+ </xsl:template>
+ <xsl:template match='sf:tableModelPartitionSource |
+ sf:tableModelStyle-ref |
+ sf:tableModelVectors |
+ sf:tableCellArrayCellsByColumn |
+ sf:tableModelTableID'/>
+
+ <xsl:template match='sf:text-storage |
+ sf:text-body |
+ sf:section |
+ sf:layout'>
+ <xsl:apply-templates/>
+ </xsl:template>
+
+ <xsl:template match='sf:stylesheet|sf:stylesheet-ref |
+ sf:container-hint |
+ sf:page-start|sf:br |
+ sf:selection-start|sf:selection-end |
+ sf:insertion-point |
+ sf:ghost-text |
+ sf:attachments'/>
+
+ <xsl:template match='*'>
+ <xsl:message>element "<xsl:value-of select='name()'/>" not handled</xsl:message>
+ </xsl:template>
+
+ <xsl:template name='rnd:find-style'>
+ <xsl:param name='ident' select='@sf:style'/>
+ <xsl:param name='para-style-name'
+ select='key("styles", $ident)/self::sf:paragraphstyle/@sf:name'/>
+ <xsl:param name='char-style-name'
+ select='key("styles", $ident)/self::sf:characterstyle/@sf:name'/>
+
+ <xsl:choose>
+ <xsl:when test='$ident = "paragraph-style-default"'/>
+ <xsl:when test='$para-style-name != ""'>
+ <xsl:value-of select='$para-style-name'/>
+ </xsl:when>
+ <xsl:when test='key("styles", $ident)/self::sf:characterstyle/sf:property-map/sf:superscript/sf:number/@sfa:number = "1"'>superscript</xsl:when>
+ <xsl:when test='key("styles", $ident)/self::sf:characterstyle/sf:property-map/sf:subscript/sf:number/@sfa:number = "1"'>subscript</xsl:when>
+ <xsl:when test='$char-style-name != "" or
+ key("styles", $ident)/self::sf:characterstyle/sf:property-map/*'>
+ <xsl:value-of select='$char-style-name'/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+</xsl:stylesheet>