Re: [xsl] Processing xsl within an included document

Subject: Re: [xsl] Processing xsl within an included document
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 13 Oct 2004 14:21:29 -0400
Brooks,

It appears you may be confusing two different features offered by XSLT:

* when you need access to another document besides your primary source, you can access it by using the document() function

* if you want to modularize your stylesheet, you have two top-level instructions, xsl:import and xsl:include, that can be used

If header.xsl provides code (a set of templates) that you want your stylesheet to use, you should be using xsl:import or xsl:include. You'd use document() only if you wanted to query into it or process some or all of it as *input* to your process. Assuming your case falls into the former category, you could adjust your code as follows:

--- main.xsl ---
<xsl:include href="include/header.xsl"/>

...

[in your template]
<xsl:variable name="testvar" select="'hello'" />
<xsl:call-template name="make-header">
  <xsl:with-param name="value" select="$testvar"/>
</xsl:call-template>
Boring main stuff

--- include/header.xsl ---
<xsl:template name="make-header">
  <xsl:param name="value"/>
  <page>
    <header>
      <h1><xsl:value-of select="$value" /></h1>
    </header>
  </page>
</xsl:template>

I hope that helps,
Wendell

At 01:33 PM 10/13/2004, you wrote:
I know that this is something of a FAQ, and I apologize.  But I've
searched the list archives and googled until the "g" key on my keyboard
begged for mercy, and I'm still stuck.

I just can't get my head around processing XSL elements inside an
included document.

Here's what I've got now:

--- main.xsl ---
<xsl:variable name="testvar" select="'hello'" />
<xsl:copy-of select="document('include/header.xsl')//page/header" />
Boring main stuff

--- include/header.xsl ---
<page>
<header>
<h1><xsl:value-of select="$testvar" /></h1>
</header>
</page>

...clearly, that's not going to work because the copy-of deep copy
thing.  The <xsl:value-of...> element is just being included verbatim in
the output.

So here's where I'm stuck.  It seems like it should be a very
straightforward operation, and I've done gymnastics with <xsl:copy> and
<xsl:apply-templates/>, but I just can't seem to make it make sense.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread