dbdesc blog

database documentation

Adding a WordML XSLT Template to Dbdesc (III)

Adding formatting styles

You can add some formatting style to every run of text <w:r></w:r>. Indeed, if you want to apply different styles to different words, those words must be placed separately inside their own <w:r> tags. Take a look at this post by Brian Jones to learn about WordML formatting.

In the following code, I’ve just added some styles and I’ve built the structure of the different sections that I plan to add to this template: tables, views, stored procedures …

[...]

<w:styles>
<w:style w:type="paragraph" w:styleId="dbdescH1" w:default="off">
<w:name w:val="dbdescH1" />
<w:pPr>
<w:pStyle w:val="dbdescH1" />
</w:pPr>
<w:rPr>
<w:sz w:val="48" />
</w:rPr>
</w:style>
<w:style w:type="paragraph" w:styleId="dbdescH2" w:default="off">
<w:name w:val="dbdescH2" />
<w:pPr>
<w:pStyle w:val="dbdescH2" />
</w:pPr>
<w:rPr>
<w:sz w:val="36" />
</w:rPr>
</w:style>
<w:style w:type="paragraph" w:styleId="dbdescH3" w:default="off">
<w:name w:val="dbdescH3" />
<w:pPr>
<w:pStyle w:val="dbdescH3" />
</w:pPr>
<w:rPr>
<w:sz w:val="24" />
<w:b val="on" />
</w:rPr>
</w:style>
</w:styles>

[...]

<w:p>
<w:pPr>
<w:outlineLvl w:val="1" />
<w:pStyle w:val="dbdescH1" />
</w:pPr>
<w:r>
<w:t><xsl:value-of select="Database/Name" /> database</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:outlineLvl w:val="2" />
<w:pStyle w:val="dbdescH2" />
</w:pPr>
<w:r>
<w:br w:type="text-wrapping" />
<w:t>Tables</w:t>
</w:r>
</w:p>
<xsl:apply-templates select="Tables" mode="build-table-details" />
<w:p>
<w:pPr>
<w:outlineLvl w:val="2" />
<w:pStyle w:val="dbdescH2" />
</w:pPr>
<w:r>
<w:br w:type="page" />
<w:t>Views</w:t>
</w:r>
</w:p>
<!-- Insert here template to build view details -->
<w:p>
<w:pPr>
<w:outlineLvl w:val="2" />
<w:pStyle w:val="dbdescH2" />
</w:pPr>
<w:r>
<w:br w:type="page" />
<w:t>Stored Procedures</w:t>
</w:r>
</w:p>
<!-- Insert here template to build store procedure details -->
</wx:sect>
<w:p>
<w:pPr>
<w:outlineLvl w:val="2" />
<w:pStyle w:val="dbdescH2" />
</w:pPr>
<w:r>
<w:br w:type="text-wrapping" />
<w:t>Index</w:t>
<w:br w:type="text-wrapping" />
</w:r>
</w:p>

[...]

The details of each section will be built in diferent XSL templates. This is the unfinished table details template. It writes each table name and its description using styles.

<xsl:template match="Table" mode="build-table-details">
<w:p>
<w:pPr>
<w:outlineLvl w:val="3" />
<w:pStyle w:val="dbdescH3" />
</w:pPr>
<w:r>
<w:t>
<w:br w:type="text-wrapping" />
<xsl:value-of select="TABLE_NAME" />
</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>
<xsl:value-of select="TABLE_DESCRIPTION" />
<w:br w:type="text-wrapping" />
</w:t>
</w:r>
</w:p>
</xsl:template>

Until now we’ve played just with plain text and some styles. Things start to become more complex when you try to use tables, headers, etc. The best way to figure out how to deal with those parts is to let Word do the work. Open a new Word document and add just one table. Save that document as XML and open it in Notepad. You will see a very complex code, but most of it can be removed. Word writes a ton of XML just to not loose any attribute or feature of a Word 2003 document, but we don’t need most of it.

The trick here is to locate the code you care about. In this case it starts with the <w:tblGrid> tag. Then cut and paste the code into our pristine Hello World sample document we saw in this post. And test it there.

I’m playing this way with Word to get my template done.

Comments