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

Re: inheritance and encapsulation in xslt? / xslt for

Subject: Re: inheritance and encapsulation in xslt? / xslt for xlink?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Tue, 22 Jul 2003 07:19:34 +0200
xsl variable inheritance
Hi Howard,

"Howard Stearns" <stearns@xxxxxxxxxxxx> wrote in message
news:3F1C8A03.6000709@xxxxxxxxxxxxxxx
> Suppose I start with an empty specialized stylesheet,
> acme-corp-2html.xsl, that xsl:imports the general stylesheet,
> us-gaap-ci-2html.xsl.  Even without defining any templates of its own,
> acme-corp-2html.xsl will handle all the elements that the general
> stylesheet can handle. That's good.
>
> However, the acme-corp instance documents uses many elements (let's say
> it could be hundreds) that are not present in generic us-gaap-ci
> instance documents. Assuming that the imported us-gaap-ci-2html.xsl just
> simplistically defines templates that match based on element names in
> the us-gaap-ci.xsd, these specialized Acme elements won't be matched by
> the imported templates.
>
> I don't see how xsl:import helps me to get the generic
> us-gaap-ci-2html.xsl templates to apply to the new elements used by Acme
> corp. (Or am I missing something?)

Yes, you are missing the fact that you could have templates that are so
general that they will work in every case.

For example, your first imported stylesheet module could contain the
identity template:

   <xsl:template match="node() | @*">
      <xsl:copy>
          <xsl:apply-templates select="node() | @*"/>
      </xsl:copy>
   </xsl:template>

this template matches every possible node with the exception of namespace
nodes, which are simply copied. It works on any xml.source without having to
know in advance its structure.

>
> I could manually determine the names of elements that are unique to
> acme-corp, and add template rules for each into acme-corp-2html.xsl.
> The bodies of these templates would be exactly the same as the templates
> of the corresponding elements in the included stylesheet. And there are
> thousands of companies like Acme Corp.


You don't need to add new templates. For example you could define a global
xsl:variable in the importing stylesheet module, that contains the names of
all elements that are to be handled by a template.

The template itself could match any element, but within its code would
process only elements, whose name is the value of one of the nodes contained
in the global variable.  Something like this:


<xsl:template match="*">
  <xsl:if test="name() = $vgNames/*">
     <!-- Process this element here -->
  </xsl:if>
</xsl:template>

And the "vgNames" xsl:variable could be defined like this:

<xsl:variable name="vgNames" select="document('')/*/myNames:myNames[1]">

and somewhere globally defined there would be:

<myNames:myNames>
  <name>name1</name>
  <name>name2</name>
  <name>name3</name>
. . . . . .  . . . . . . . . . . .. . . .
  <name>nameN</name>
</myNames:myNames>



>
> I want to be able to write versions of generic stylesheets (like
> us-gaap-ci-2html.xsl) that will work no only for us-gaap-ci.xsd instance
> documents, but also for any documents derived from us-gaap-ci that
> define their own more specialized elements.

The examples above show that this can be done. Probably if you provide (the
simplest possible and minimal) complete example people will produce the
solution for you in no time.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.