Document! X and HelpStudio supports transforming structured XML content to HTML using XSLT. Using XSLT to transform XML / SQL comments allows you to further customize the output generated from a given set of content. It also allows you to enter more complicated and structured XML / SQL source comments, the output of which can be customized without making changes to the comment itself.
Below is an example of an XML source comment and an equivalent Transact SQL comment that we would like to appear in table form in the generated output.
XML |
Copy Code |
---|---|
/// <HistoryContent> /// <History> /// <HistoryEntry Date="1/1/2011" Name="Author 1" type="New" Description="Created"/> /// <HistoryEntry Date="1/5/2011" Name="Author 2" type="Fix" Description="Edited" /> /// </History> /// </HistoryContent> |
SQL |
Copy Code |
---|---|
-- ##HISTORYCONTENT <History><HistoryEntry Date="1/1/2011" Name="Author 1" type="New" Description="Created"/><HistoryEntry Date="1/5/2011" Name="Author 2" type="Fix" Description="Edited content" /></History> |
XSLT |
Copy Code |
---|---|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="History"> <table> <tr> <th>Date</th> <th>Name</th> <th>Type</th> <th>Description</th> </tr> <xsl:apply-templates /> </table> </xsl:template> <xsl:template match="HistoryEntry"> <tr> <td> <xsl:value-of select="@Date"/> </td> <td> <xsl:value-of select="@Name"/> </td> <td> <xsl:value-of select="@type"/> </td> <td> <xsl:value-of select="@Description"/> </td> </tr> </xsl:template> </xsl:stylesheet> |
<!--DXMETADATA start type="TaggedComment" source="Item" id="HistoryContent" format="%%scrap:name=_COLLAPSIBLE_HEADER,idprefix=historycontent,caption=History%%%%comment%%</div>" -->History<!--DXMETADATA end -->
Be sure to only include the section on Page Types that correspond to the Item Types you selected when you created the Custom Content Item Type in "Step 1: Create a Custom Content Item Type" above.
Open the Build Profile Editor and on the Templates page choose the custom Template you created above.
Now the custom content item type has been created and a custom Template created and selected in the Build Profile Editor the custom Content Item Type content can be viewed in the Content File editor in the same way as the built in content item types (summary, remarks etc).
The transformed output from this example will look like the following table:
Date | Name | Type | Description |
---|---|---|---|
1/1/2011 | Author 1 | New | Created |
1/5/2011 | Author 2 | Fix | Edited content |