I thought that perhaps it was time to put a little back into the
TiddlyWiki community, so here is a description of how we use it, and a
little of the XSLT code that we use.  I though that it might be useful
for anybody else considering using TiddlyWiki in a similar way.

We use TiddlyWiki for database documentation (Data Management Wiki or
DM Wiki for short); the mechanism for building the TiddlyWiki file is
fully automated and is part of the same process that generates:
Database Build Scripts, Application Include files for Constants and
other artefacts.

The advantage of using TiddlyWiki in this way is that it gives us a
searchable and hyper-linked, single file standalone "document" that is
easily packaged into a database release and can be shared with
external groups such as Customers and Distributors.

In the first stage of this process we generate an XML file containing
the meta-data about a database release.  This is XSLT transformed into
the Oracle, SQL Server and DB2 database definition scripts and the
Include files.

The XML file is also XSLT transformed into a TiddlyWiki HTML file that
contains only the <html><body><div id="storeArea"> content - (where
the User Defined Tiddlers are stored); this file can be imported into
a TiddlyWiki using the Backstage Import process.

Until recently that was exactly what we did - open a copy of a
Template TiddyWiki file and import.  The Template TiddlyWiki is
customised to suit the company styling and includes various plug-ins
and other common tiddlers.  Due to the volume of data involved this
can only be done in Firefox as the other browsers all fail for various
reasons.  [We are looking at using TiddlyWeb with the Template and
Content in separate Bags and being merged using recipes, and that is
where we will go when we can automatically remotely create and
populate a bag and create a parent recipe].


What I thought that I would share is an intermediate method that we
use to merge the Template and DB Wiki files into a final DM Wiki
without having to open the TiddlyWiki in a browser at all.

This is also an XSLT transformation that takes the Template Wiki as
the source, and references the DB Wiki using a parameter.  It is very
simple but there are a couple of tricks that people may find
interesting.

The full XSLT is listed below:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:fn="http://www.w3.org/2005/xpath-functions"; xmlns:html="http://
www.w3.org/1999/xhtml">
        <xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/
DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//
EN" indent="no" />
        <xsl:param name="src" select="'WikiContent.html'"/>

        <xsl:template match="/">
                <xsl:apply-templates/>
        </xsl:template>

<!-- Copy storeArea Div from both Template and Source-->

        <xsl:template match="html:div[@id='storeArea']">
                <div id="storeArea">
                        <xsl:apply-templates select="node()"/>
                        <xsl:apply-templates 
select="document($src)//div[@id='storeArea']/
node()"/>
                </div>
        </xsl:template>

<!-- Copy everything else without modification -->
<!-- Except the xml:space="preserve" generated by altova sw-->

        <xsl:template match="@*:space"></xsl:template>

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

The little tricks that I thought should be mentioned:

xmlns:html="http://www.w3.org/1999/xhtml"; in the stylesheet tag is
required because all elements in an xhtml file (TiddlyWiki) are in the
http://www.w3.org/1999/xhtml namespace - without this declaration the
elements and attributes are invisible to the xslt; you can't match on
"div", but you can on "html:div"

doctype-system and doctype-public are required in the output
definition to correctly recreate the doc-type declaration in the final
Wiki file - you can't copy these using XSL because they are not part
of the source document.

xsl:param src (referenced later as $src) is used for the name of the
file where the Wiki content comes from - an XSLT normally has a single
input and a single output, but by providing the name of another file
as a parameter we can open that other file at the same time using the
document() function to give two or more sources during the
transformation.

The templates that match on "/" and "@*|node()" are the commonly used
"Copy Everything" transformations, and by themselves will copy
everything in the source document [almost] without change.

The template that matches on "html:div[@id='storeArea']" is triggered
when the processing gets to the storeArea div in the Template Wiki -
it copies of all of the child elements (the Template Tiddlers) and
then copies all child elements from the storeArea div in the file
$src.  This doesn't use the html prefix, but that is only because it
isn't used in our generated Wiki Content file. The final Wiki will
therefore have all Template Tiddlers followed by all Wiki Content
tiddlers.

The template that matches on "@*:space" might only be necessary when
using the Altova XSLT processor.  The output was supposed to be a
straight copy of the source wasn't - it had added hundreds of
xml:space="preserve" attributes.  There was nothing that I could find
on the web about preventing this, but I finally worked out that the
attribute was being added when any html element that looked like
formatted text appeared in either of the sources - which is all of our
tiddlers and much of the core TiddlyWiki too.  There is no way to
prevent this as it is essential to the XSLT processor functioning
correctly for these elements, but it doesn't have to be output; this
template is triggered for all of the space attributes and outputs them
as a zero length string.


That's it.  I am not suggesting that it is perfect, but it meets out
needs.  Three immediately obvious enhancements are:

a) The combined set of Tiddlers are not sorted as they would be after
doing an Import in TiddlyWiki - this doesn't seem to matter.

b) There would be duplicate Tiddlers if the Template and Wiki Content
had clashing tiddlers - during a TiddlyWiki Import the Template one
would typically be overwritten, but as we are careful to avoid naming
clashes this isn't a problem.

c) The stylesheet only preserves whitespace within elements - it
doesn't keep it between elements, so there is some compression of the
TiddlyWiki file as lots of tabs, cr and spaces are removed.  This
makes the final file slightly smaller and faster at the cost of making
it less readable - but as we don't even edit this file again, let
alone go into the source, that doesn't matter either.

If anybody is considering automatic production of TiddlyWiki files - I
hope this helps

Matt Flower

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywikidev?hl=en.

Reply via email to