OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook] docbook5 and adding elements (long)


   Okay, I've given Relax NG a try, and I'm stumped with it too.  I've
started with the assembly-language example that has been pointed out
to me, and it seems to be promising.  I'm still missing a step, so a
correction would be most welcome! :)

   Here's a sample session with error message that I'm getting:

C:\kells\docbook1\assembly_example>create_pdf.bat

C:\kells\docbook1\assembly_example>java -jar c:\docbook\bin\trang.jar asmbook.rn
c asmbook.rng

C:\kells\docbook1\assembly_example>xsltproc -o asmbook.xsl rng2customization.xsl
 asmbook.rng docbook.rng

C:\kells\docbook1\assembly_example>xsltproc -o asmbook.fo asm_db.xsl asmbook.xml

WARNING: cannot add @xml:base to node set root element.  Relative paths may not
work.
Making portrait pages on USletter paper (8.5inx11in)
register encountered in para, but no template matches.
register encountered in para, but no template matches.
register encountered in para, but no template matches.
instruction encountered in para, but no template matches.


asmbook.xml
==========
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook"; version="5.0">
<title>Assembler guide</title>

<para><register>AX</register> is 16bit register. You can use registers
<register>AH</register> and <register>AL</register> to access its
higher and lower parts.  <instruction>MOV</instruction> is instruction
for moving data between your registers and memory.</para>

</article>

asmbook.rnc (modified with my local docbook.rnc file)
========================================
default namespace = "http://docbook.org/ns/docbook";
namespace db = "http://docbook.org/ns/docbook";
namespace r  = "http://nwalsh.com/xmlns/schema-remap/";

# new element for CPU registers
db.register =
  [ r:remap [ db:emphasis [ role = "bold" ] ] ]
  element register { text }

# new element for instructions
db.instruction =
  [ r:remap [ db:code [ ] ] ]
  element instruction { text }

# combined pattern
asm.inlines = db.register | db.instruction

include "file:///c:/docbook/lib/docbook-5.0b5/rng/docbook.rnc"
  {
    # register and instruction are permitted everywhere in inline content
    db.general.inlines |= asm.inlines
  }

rng2customization.xsl (Can this be replaced with something more automagic?)
=========================================================
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
		xmlns:xslo="http://www.w3.org/1999/XSL/TransformAlias";
		xmlns:r="http://nwalsh.com/xmlns/schema-remap/";
		xmlns:rng="http://relaxng.org/ns/structure/1.0";
		xmlns:exsl="http://exslt.org/common";
		extension-element-prefixes="exsl"
		exclude-result-prefixes="exsl rng r"
		version="1.0">

<xsl:output indent="yes"/>

<xsl:namespace-alias stylesheet-prefix="xslo" result-prefix="xsl"/>

<xsl:template match="/">
  <xslo:stylesheet version="1.0">
    <xsl:attribute name="exsl:dummy"
xmlns:exsl="http://exslt.org/common";>dummy</xsl:attribute>

    <xslo:template match="/" mode="stripNS">
      <xslo:variable name="unspecialized">
	<xslo:apply-templates mode="remap"/>
      </xslo:variable>
      <xslo:apply-templates
select="exsl:node-set($unspecialized)/node()" mode="stripNS"/>
    </xslo:template>

    <xsl:for-each select="//rng:element[r:remap]">
      <xslo:template match="*[local-name() =
'{@name}'][namespace-uri() = '{//ancestor-or-self::*[@ns][1]/@ns}']"
mode="remap">
	<xsl:choose>
	  <xsl:when test="r:remap//r:content">
	    <xsl:apply-templates select="r:remap/node()" mode="copy"/>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:element name="{local-name(r:remap/*[1])}"
namespace="{namespace-uri(r:remap/*[1])}">
	      <xsl:copy-of select="r:remap/*[1]/@*"/>
	      <xslo:apply-templates mode="remap"/>
	    </xsl:element>
	  </xsl:otherwise>
	</xsl:choose>
      </xslo:template>
    </xsl:for-each>

    <xslo:template match="node()|@*" mode="remap">
      <xslo:copy>
	<xslo:apply-templates select="node()|@*" mode="remap"/>
      </xslo:copy>
    </xslo:template>

  </xslo:stylesheet>

</xsl:template>

<xsl:template match="node()|@*" mode="copy">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" mode="copy"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="r:content" mode="copy">
  <xslo:apply-templates mode="remap"/>
</xsl:template>

</xsl:stylesheet>

asm_db.xsl (to tie together the docbook.rng and asmbook.rng)
==============================================
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

<xsl:import href="file:///c:/docbook/lib/docbook5-xsl-1.72.0/fo/profile-docbook.xsl"/>

<xsl:import href="file:///c:/kells/docbook1/assembly_example/asmbook.xsl"/>

</xsl:stylesheet>

create_pdf.bat
==========
java -jar c:\docbook\bin\trang.jar asmbook.rnc asmbook.rng

xsltproc -o asmbook.xsl rng2customization.xsl asmbook.rng docbook.rng

xsltproc -o asmbook.fo asm_db.xsl asmbook.xml








On 3/13/07, Dick Hamilton <rlhamilton@frii.com> wrote:
> Kells,
>
> I haven't worked with the DTD for DocBook 5, just the Relax NG schema,
> so I can't help with the specific problem you're having.  With any luck
> someone will post a quick fix.
>
> But, if you can work with the Relax NG schema version of DocBook, here
> are a couple of resources that should be helpful:
>
> http://www.docbook.org/docs/howto/
>
> This guide has a section about customizing the DocBook 5 Relax NG
> schema.
>
> The following reference discusses customizing DocBook 5 stylesheets
> once you've modified a schema:
>
> http://xmlguru.cz/2006/03/easy-docbook-specialization
>
> It also points to an article by Norm Walsh that may be helpful.
>
> I suspect that the combination of these references will get you where
> you need to go if you can use Relax NG instead of DTDs.
>
> Good luck.
>
> Dick Hamilton
> rlhamilton@frii.com
>
> > -----Original Message-----
> > From: Kells Kearney [mailto:keruzu@gmail.com]
> > Sent: Tuesday, March 13, 2007 6:13 PM
> > To: docbook@lists.oasis-open.org
> > Subject: [docbook] docbook5 and adding elements (long)
> >
> >
> >   I've taken a look through the e-mail archives, and I've tried
> > googling, but I'm unable to find an answer to why I can't do something
> > that should be quite simple. :(  I've found documentation for how to
> > do it using Docbook 4.x (and had no luck using it with Docbook 5), but
> > it *seems* like a good thing to do it in Docbook 5. (Right?)
> >
> >   I'm hoping that some kind soul can help me understand what it is
> > that I'm doing wrong.  I think that all I need is one good example.
> > Thanks in advance!
> >
> >
> > kells
> >
> >
> > What I'm trying to do:
> > ================
> >    I would like to be able to create an application-specific prompt to
> > create documentation for the application.  The prompt looks like:
> >
> >   app: server_name>
> >
> >    where I'd like to define server_name in an entity as an attribute
> > with a reasonable default.  To illustrate, I'd like to be able to
> > write:
> >
> >   <app> <command> bleh </command>
> > <variable>colour</variable>=<replaceable>blue</replaceable>
> >   </app>
> >
> >   <app server="server2" > <command> bleh </command>
> > <variable>colour</variable>=<replaceable>green</replaceable>
> >   </app>
> >
> >   and have the output look something like:
> >
> >     app: server1> bleh colour=blue
> >     app: server2> bleh colour=green
> >
> > Where I am so far
> > ==============
> > Input file: test.xml
> > ----------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE book SYSTEM "app.dtd" >
> >
> > <book version="5.0"
> >       xmlns:xlink="http://www.w3.org/1999/xlink";
> >       xmlns:xi="http://www.w3.org/2001/XInclude";
> >       xmlns:svg="http://www.w3.org/2000/svg";
> >       xmlns:mml="http://www.w3.org/1998/Math/MathML";
> >       xmlns:html="http://www.w3.org/1999/xhtml";
> >       xmlns:db="http://docbook.org/ns/docbook";
> > >
> >
> > <chapter>
> > <title>Hello world!</title>
> > <para>Sample explanatory text here</para>
> >
> >   <app server="server2" > <command> bleh </command>
> > <variable>colour</variable>=<replaceable>green</replaceable>
> >   </app>
> >
> > </chapter>
> > </book>
> >
> >
> >
> > My DTD app.dtd:
> > ------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <!--  Add the "app" element to something hopefully similar to
> > what I want. :)
> >       If I understand things correctly, this inserts the element
> > definition into
> >       the right spots in the DocBook grammar (aka DTD).
> >   -->
> > <!ENTITY % local.tech.char.class "|app" >
> >
> > <!--   Other documentation I've seen suggests taking the
> >         docbook dtd, making a parameter entity and invoking it here.
> >         It goes badly for me if I do
> >
> > <!ENTITY % DOCBOOK SYSTEM
> > "file://c:/docbook/lib/docbook-> 50b5/dtd/docbook.dtd">
> >
> > %DOCBOOK;
> >
> >        So I can't use the
> > above. Right?
> >
> > -->
> >
> > <!--  Create the "app" element  -->
> > <!ELEMENT app (#PCDATA|filename|replaceable|constant|parameter)* >
> >
> > <!-- Set a default server name  -->
> > <!ATTLIST app server ENTITY "server1" >
> >
> >
> >
> > My app.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";
> >
> > xmlns:db="http://docbook.org/ns/docbook";
> > >
> >
> > <!-- Here's where it starts to get really scary for me. :)
> >       This is also wrong, but I *think* shows what I want to do.
> > -->
> > <xsl:template match="app">
> >         <xsl:call-template name="db:prompt">
> >               <xsl:value-of select="@server" />
> >         </xsl:call-template>
> >         &amp;
> >       <xsl:apply-templates select="." />
> > </xsl:template>
> >
> > </xsl:stylesheet>
> >
> >
> > Invocation with xsltproc
> > ==================
> > xsltproc --nonet --xinclude --output test.fo app.xsl test.xml
> >


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]