[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to write modular/extensible Xslt?

Subject: How to write modular/extensible Xslt?
From: Manuel Holtgrewe <purestorm@xxxxxxxxxxx>
Date: Tue, 23 Dec 2003 22:51:57 +0100
modular xsl
Hi

I have a problem with writing a modular Xslt sheet for merging trees:

In our "node definition files" we have some <node:definition /> tags
that may have children "node:definition" tags. However, you can also
include such tags using "node:include" tags with the attribute 
"definition".

Consider the following:

== including.ndf.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<node:definition
    xmlns:node="http://www.binarycloud.com/ns/node"
    version="2.0" id="top">
  <children>
    <node:include definition="included.ndf.xml" id="including">
      <param name="foo">bar</param>
      <param name="newkey">yet another value</param>
    </node:definition>
  </children>
</node:definition>
==

== included.ndf.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<node:definition
    xmlns:node="http://www.binarycloud.com/ns/node"
    version="2.0" id="included">
  <param name="foo">oldvalue</param>
  <param name="oldkey">some value</param>
</node:definition>
==

Now, I want to include the included.ndf.xml and merge the root tag
"node:definition" from included file with the "node:include" file
(including tag has is overriding). This is not a big problem and I 
already have a template for this using recursive "xsl:call-template"
calls:

== merge.xsl fragment
<!--
  node:include tags are threated specially: The two trees are
  to be merged.
-->
<xsl:template match="*[name() = 'node:include']">
    <!-- try to retrieve the included ndf -->
    <xsl:param name="bc-app-path" />
    <xsl:variable name="path" select="concat($bc-app-path,@definition)" />
    <xsl:variable name="ndf" select="document($path)" />

    <!-- get shortcuts to the including and included node -->
    <xsl:variable name="including" select="." />
    <xsl:variable name="included" select="$ndf/node:definition" />
        
    <!-- Merge the including node:include and the included 
         node:definition tags to a node:definition tag. -->
    <xsl:call-template name="merge-include">
        <xsl:with-param name="nodes1" select="$included" />
        <xsl:with-param name="nodes2" select="$including" />
    </xsl:call-template>
</xsl:template>
== 

Where the template merge-include merges all param and section tags.
"section" tags are simple, named containers for param tags.

Now, my question: How can I keep such a template modular so I can add
other tags to merge, too. We use different namespaces for different
packages of our framework and the package "form" introduces a namespace
"form" with new tags. Now, I want to merge one "<form:validator>" list
in each included and including tag for the resulting tag. How can I do
so easily? Is it possible to do so without having to touch the template
every time I add new tags to be merged?


Manuel

-- 
Unix definitely is a user friendly operating system.
- It is only picky with its friends.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.