[xsl] xsl:import and xsl:apply-imports

Subject: [xsl] xsl:import and xsl:apply-imports
From: Mike Ferrando <mikeferrando@xxxxxxxxx>
Date: Thu, 27 Oct 2005 06:12:37 -0700 (PDT)
Friends,
I had a question about xsl:apply-imports.

Stylesheet s_a.xsl
  imports: stylesheet s_b.xsl and s_c.xsl

XSLT version 1.0
Instant SAXON (6.5.3) or SAXON 6.5.4

=== s_a.xsl xsl: ===

<xsl:import href="s_b.xsl"/>
<xsl:import href="s_c.xsl"/>

<xsl:template match="//root">
  <xsl:apply-templates select="subset1"/>
  <xsl:apply-imports select="subset2 | subset3"/>
</xsl:template>

<xsl:template match="subset1">
</xsl:template>

<xsl:template match="p">
</xsl:template>

=== xml: ===

<root>
  <subset1><p></p></subset1>
  <subset2><p></p></subset2>
  <subset3><p></p></subset3>
</root>


My goal is as follows:

to process child::subset1 and all descendants in stylesheet A only.
to process child::subset2 and all descendants in stylesheet B only.
to process child::subset3 and all descendants in stylesheet C only.

If I use apply-imports in stylesheet A, does that mean that the
common descendant elements of subset2 and subset3 could be processed
by either imported stylesheet (B or C)?

This is a simplified example, but I want to avoid writing modes and
predicates, etc. for templates that process descendant elements that
have the same element names in these stylesheets. So, I want to
transform the subset1/p differently than the subset2/p and so on. My
hope is that I can simply write templates to so this in the
stylesheets designated for each child of the root element. Once
inside the stylesheet (B or C), I can be confident that the
descendants will be processed only in that particular stylesheet.

Reading the various definitions of xsl:import and xsl:apply-imports,
it did not seem clear to me how the above can be done if xsl:import
imports the stylesheet (B or C) into stylesheet A. Doesn't that mean
that all the templates are available to any node being processed by
stylesheet A?

I have been successful using xsl:import using modes for a test suite
for the Library of Congress MARC 21 Holdings Format (full version) I
created with namespace and transformation of XML into HTML using
three batch files (titlepage to last appendices). I hope this will
serve as a proof of concept model for the future of MARC 21 Formats.

http://lcweb2.loc.gov/music/eadmusic/marcdoc_conv05/marcdoc_conv_ts_05.htm


 My bench tests so far have yielded good results without using
xsl:imports, but I want to change the stylesheet designs so that the
I can accomplish better transformations.

Mike Ferrando
Library Technician
Library of Congress
Washington, DC
202-707-4454 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread