Re: [xsl] stylesheet organisation

Subject: Re: [xsl] stylesheet organisation
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 03 Sep 2011 10:16:40 -0400
I've been told off-line that my example was poorly illustrated having used a stylesheet as my input XML document.

Here is a revision to the example illustrating an important difference between <xsl:include> and <xsl:import>. As Mike mentioned, there are other important differences, but the incorrect information posted to the archive was related to matching.

In this example the generic "xslt" command takes three arguments: input file, stylesheet file, output file. In the DOS command line "con" is the console for the output.

I hope this helps.

. . . . . . . . . . Ken

t:\ftemp>type doc.xml
<doc/>

t:\ftemp>
t:\ftemp>type A.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:template match="/" priority="1000">
  Stylesheet A
</xsl:template>

</xsl:stylesheet>
t:\ftemp>
t:\ftemp>type B.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:include href="A.xsl"/>

<xsl:template match="/" priority="1">
  Stylesheet B
</xsl:template>

</xsl:stylesheet>
t:\ftemp>
t:\ftemp>type C.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:import href="A.xsl"/>

<xsl:template match="/" priority="1">
  Stylesheet C
</xsl:template>

</xsl:stylesheet>
t:\ftemp>
t:\ftemp>xslt doc.xml B.xsl con
<?xml version="1.0" encoding="utf-8"?>
  Stylesheet A

t:\ftemp>
t:\ftemp>xslt doc.xml C.xsl con
<?xml version="1.0" encoding="utf-8"?>
  Stylesheet C

t:\ftemp>

At 2011-09-03 09:54 -0400, I wrote:
In my haste I described my two examples in the text backwards: in fact B.xsl includes A.xsl and C.xsl imports A.xsl. The template rule in B.xsl is overridden by match priority by the template rule in A.xsl. The template rule in C.xsl overrides by import precedence the template rule in A.xsl.

The stylesheet fragments are still correct illustrating the difference between import and include, I just wrote the description of the example incorrectly.

Please forgive my oversight due to my haste.

. . . . . . . . Ken


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread