Save as Word Document | Find | English | Portugues(Brasil)

Creating Layouts for XMLNuke
Creating Structural Snippets

How to create Structural Snippets.

Table of contents
1. Creating Layouts with XMLNuke
2. Creating Structural Snippets
3. Creating Template Snippets

On this page
Structural Snippets
Creation Example


Structural Snippets

Structural snippets are called this since they behave differently on the XML nodes by permitting iteration through the elements and generating their own definition. These Snippets should always be within the area number 2 (see figure in previous chapter) and normally use the xsl:for-each commands to locate the elements:

The most common uses for this type of snippet are:

  • Definition of MENUS
  • Definition of Data Blocks

Creation Example

To create this Snippet, it's important to observe the XML document produced by XMLNuke. A standard structure is defined below.

Standard structure of an XML document
<page>

	<!-- PAGE HEADER -->
	<meta>
		<title></title>
		<abstract></abstract>
		<created></created>
		<modified></modified>
		<keyword></keyword>
		<groupkeyword></groupkeyword>
	</meta>

	<!-- INFORMATION AREA -->
	<blockcenter>
		<title>Snippets Estruturais</title>
		<body>
			<p></p>
		</body>
	</blockcenter>

	
	<!-- THIS BLOCK IS ADDED BY XMLNUKE -->
	<!-- YOU SHOULD NOT CREATE THIS BLOCK -->
	<group>
		<id>IDMENU</id>
		<title>Title of menu group</title>
		<keyword>all</keyword>

		<page>
			<id>home</id>
			<title>Site Documentation</title>
			<summary>Site Documentation for XMLNuke.</summary>
		</page>
	</group>

</page>

It's important to note that to build this type of Snippet, you must work directly with XPATH. XPATH indicates the position of a specific XML node within the document. For example, the "blockcenter" node is within the "page" and it is not within any other. Thus, the XPATH would be /page/blockcenter.

With this information, see an example of BLOCKCENTER. IMPORTANT: All the structural snippets should be created EXACTLY in the position which we want them to appear.

Snippet to create a 'blockcenter'
<xsl:for-each select="page/blockcenter">
	<h1><xsl:value-of select="title"/></h1>
	<xsl:apply-templates select="body"/>
</xsl:for-each>

In this example, the for-each looks for all of the "blockcenter" nodes within a "page", and for each of these will write the HTML commands within them. Note, however, that there are two other commands: "value-of" which takes the value of "title" that is within a "blockcenter" and "apply-templates" that gives the information to search for template snippets (next chapter).

Below is another example on how to build a menu. Observe that the menu structure does NOT have to be included when creating the document, because XMLNuke automatically includes an adequate menu structure.

Snippet for a simple menu
<xsl:for-each select="page/group">
	<h1><xsl:value-of select="title"/></h1>
	<ul>
	<xsl:for-each select="page">
	<li>
	   <a><xsl:attribute name="href">
		<xsl:value-of select="id" />
	      </xsl:attribute>
	   </a></li>
	</xsl:for-each>
	</ul>
</xsl:for-each>

Previous
Creating Layouts with XMLNuke
Next
Creating Template Snippets