Page 1 of 1

Format for auto ids.

Posted: Tue Aug 25, 2009 9:22 pm
by xsaero00
I am looking at the auto generation of xml:id attribute in DocBook 5. The only documented variables for "ID Pattern" are ${localName} and ${uuid}. Is these more supported variables?

I am shooting for something like:

Code: Select all

${localName}.${elemPosition}
so my xml will be like

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbook.rng" type="xml"?>
<book xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<chapter xml:id="chapter.1">
<title>Chapter Title</title>
<subtitle>Subtitle of Chapter</subtitle>
<sect1>
<title>Section1 Title</title>
<subtitle>Subtitle of Section 1</subtitle>
<para>Text</para>
</sect1>
</chapter>
<chapter xml:id="chapter.2">
<title>Chapter Title</title>
<subtitle>Subtitle of Chapter</subtitle>
<sect1>
<title>Section1 Title</title>
<subtitle>Subtitle of Section 1</subtitle>
<para>Text</para>
</sect1>
</chapter>
</book>

Re: Format for auto ids.

Posted: Wed Aug 26, 2009 10:38 am
by sorin_ristache
Hello,

In the current version only the variables ${localName} and ${uuid} are available for the ID pattern. We will consider allowing the creation of new variables or maybe the specification of the ID value using a custom Java class.


Regards,
Sorin

Re: Format for auto ids.

Posted: Wed Aug 26, 2009 6:24 pm
by xsaero00
In the mean time can I just override the behavior of the classes that do the id generation?

Re: Format for auto ids.

Posted: Thu Aug 27, 2009 11:45 am
by sorin_ristache
Hello,

You can modify the class ro.sync.ecss.extensions.docbook.id.Docbook5UniqueAttributesRecognizer and return an instance of your modified version in the method ro.sync.ecss.extensions.api.ExtensionsBundle.getUniqueAttributesIdentifier(). You have to add your extension on the Classpath tab of the dialog for editing a document type and set your ExtensionBundle class on the Extensions tab of the same dialog.


Regards,
Sorin

Re: Format for auto ids.

Posted: Thu Aug 27, 2009 6:07 pm
by xsaero00
Thanks. It seems like I'll have to override the docbook ExtensionBundle.

Any idea on how to do something like this:

Original Document

Code: Select all


<book xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<chapter xml:id="chapter.1">...<xref linkend="chapter.2"/></chapter>
<chapter xml:id="chapter.2">...</chapter>
</book>
then i insert another chapter in the middle a get this

Code: Select all


<book xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<chapter xml:id="chapter.1">...<xref linkend="chapter.3"/></chapter>
<chapter xml:id="chapter.2">New Chapter</chapter>
<chapter xml:id="chapter.3">...</chapter>
</book>

Re: Format for auto ids.

Posted: Thu Aug 27, 2009 6:31 pm
by sorin_ristache
Do you mean to insert a new chapter with the ID chapter.2 and rename the ID of the existing chapter from chapter.2 to chapter.3 in both the xml:id and the linkend attribute? You have to write an Author extension that inserts a chapter element at the cursor location (for inserting the new chapter.2 element) and at the same time finds the next sibling chapter element and the xref element that has the same linkend attribute as the xml:id attribute of the sibling chapter element. You find both elements using authorAccess.getDocumentController().findNodesByXPath(). After that you change both attribute values (chapter/@xml:id and xref/@linkend).


Regards,
Sorin