Serna plugin development

Problem

I spent a couple of days figuring out some weird behaviour of Serna. When trying to develop my own plugin, it always rendered my content in editable text fields, rather than word-processor-like inline editable text. Looking at the FO-tree dump, it appeared to be rendered using the serna-extensions.

Strip-down

I decided to strip-down the resume project, up to the level at which my own plugin was built up, to see where the text fields would show up.

The trigger for getting the editable text fields, is removing this line from the source resume xml:

<!DOCTYPE resume PUBLIC "-//Sean Kelly//DTD Resume  1.5.1//EN" "http://xmlresume.sourceforge.net/dtd/resume.dtd" []>

A clue on the web?:

It’s not a bug  per se.  That final decision rests with the folks at Syntext.  Serna has the capability to support entities (which XML Schema does not have).  In order to do get that capability, Serna uses in-line DOCTYPE.


That said, to process those documents in the Toolkit one needs to do one of the following:

a) remove the DOCTYPE from the XML docs; you get XSD validation

b) remove xmlxs:xsi namespace and xsi:noNamespaceSchemaLocation attribute from the XML docs;  you get DTD validation

c) modify the DTDs in the Toolkit  to include xmlxs:xsi namespace and xsi:noNamespaceSchemaLocation attribute;  you get DTD validation


Changing the XML parser parameters will not do anything useful since it is dependent on what appears in the XML docs.  The easiest one to do ay this point would be to modify the DTDs in the Toolkit.  That would allow you to process the documents without having to modify each one them.

Further stripping down of the resume example shows how the DTD declares a FIXED xmlns-attribute to the top-level element. Setting or unsetting this attribute would cause Serna to behave differently regarding presentation of the element text in wysiwyg-view. After removing the DTD alltogether, the xmlns-attribute doesn’t seem to be needed at all.

Bare-bone Serna plug-in

This is the complete specification of a bare-bone Serna plug-in that can be used for displaying, editing and saving xml-files using a custom stylesheet.

Serna Document Template (sdt)

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE  t:document-template PUBLIC "-//Syntext//DTD Syntext Document Template  V2.0//EN" "doctemplate2.dtd">
<t:document-template  xmlns:t="http://www.syntext.com/Extensions/DocTemplate-2.0">
 <t:name>Resume</t:name>
 <t:category>XML  Resume</t:category>
 <t:xml-stylesheet>$SERNA_TEMPLATE_DIR/xsl/resume.xsl</t:xml-stylesheet>
 <t:xml-schema>$SERNA_TEMPLATE_DIR/xsd/resumex.xsd</t:xml-schema>
 <t:root-elements>resume</t:root-elements>
 <t:category-pixmap>resume_1_5_1_template</t:category-pixmap>
 <t:rootelem-guess-string>resume</t:rootelem-guess-string>
 <t:document-skeleton>
  <t:name>Resume</t:name>
 </t:document-skeleton>
</t:document-template>

XML Schema (resumex.xsd)

<?xml  version="1.0"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element  name="misc">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="para"   maxOccurs="unbounded"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element  name="para">
  <xs:complexType mixed="true" />
 </xs:element>
 <xs:element  name="resume">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="misc"   maxOccurs="unbounded"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

Stylesheet (resume.xsl)

<xsl:stylesheet  version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:include  href="http://www.syntext.com/xslbricks-1.0/fo/fo.xsl"/>

<xsl:strip-space  elements="*"/>

<xsl:template name="heading">
 <fo:block>
  <xsl:value-of  select="local-name(.)"/>
 </fo:block>
</xsl:template>

<xsl:template  match="para">
 <fo:block>
  <xsl:call-template name = "bold.inline"/>
 </fo:block>
</xsl:template>

<xsl:template  match="misc">
 <fo:block>
 <xsl:call-template name="heading"/>
 <xsl:apply-templates/>
 </fo:block>
</xsl:template>

<xsl:template  match="resume">
 <xsl:call-template name="div"/>
</xsl:template>

</xsl:stylesheet>

Example XML

<?xml version='1.0'  encoding='UTF-8'?>
<resume>
 <misc>
  <para>User  Documentation developer</para>
  <para>Strip-downer</para>
 </misc>
</resume>

Conclusion

I seem to have solved my problem, but I still don’t understand why Serna behaves the way it does. Anyway, lesson learned (once again): if a stylesheet is behaving strange, 9 to 10 a namespace is in your way!

[Update!] Conclusion 2

I must have been completely deceived…. now it seems more like that the element definition in the xsd controls the behaviour of Serna:
This definition renders text fields:

<xs:element name="hyperlink"  type="xs:string" minOccurs="0" maxOccurs="1"/>

And omitting the ‘type=”xs:string”’ renders wordprocessor-style inline text:

<xs:element  name="title" minOccurs="0" maxOccurs="1"/>
Advertisements

2 thoughts on “Serna plugin development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s