Assembling XML data from multiple subset XML document files using XSLT

When dealing with XML formatted content, rarely does all the data that one requires come from a single source. The main justification for encoding data in XML format is the ability to share and exchange this information with disparate systems on different platforms. This implies that more often that not, we will be pulling XML data from more than one source for any single application.

XSLT can be used to manipulate and combine data from multiple XML sources into a new file. In this document, we will review the process of calling using smaller XML data sources to build a new XML data source.

Including an XML data set into another
If we step away from the details of how to code the process, the process is a common programmatic procedure that is used in many languages to declare data sources or logical function definitions, and then use them within the local logic or data structure.

If you have one or more files with data that you would like to include as part of a larger file
Example:

If the following is the content of navigation.xml

<mynavigation>
<menu_item>
<label>XSLT to manipulate XML</label>
<link_href></link_href>
<description>This resource provides an overview and a detailed discussion on how to use XSLT to manipulate XML data</description>
</menu_item>
<menu_item>
<label>XML format future</label>
<link_href></link_href>
<description>Discover how XML is in the future of boundless data exchange and storage</description>
</menu_item>
<mynavigation>

To include this data as part of another XML process, you have to define this data source, and then call it within the document as follows.

At the top of your new document, and within a DOCTYPE declaration, and then within the data contained in this document, insert the imported data as a node as shown in the example below.

<!DOCTYPE xsl:stylesheet [
<!ENTITY main_navigation SYSTEM 'navigation.xml'>
]>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<div id="main_navigation">
&main_navigation;
</div><!-- / main_navigation -->
</xsl:template>
</xsl:stylesheet>

Needless to declare, you can use this process to include data from more than one constituent XML source by repeating the process as many times as necessary.

The syntax in this case is very similar to creating a character entity (such as &amp; or &copy) and then using it in the document
Valid XHTML 1.0 Strict
This site is accepts Oped ID authentication for login
This Website is Built Using Semantic Markup and Cascading Style Sheets (CSS)
Some usage rights are reserved, please contact us for approval before using it