subclassing in XSLT

Andy Fish

Usenet Archive
Joined
Dec 30, 2002
Messages
605
Reaction score
0
Hi,

I'm trying to achieve something like subclassing in XSLT, by which I mean that I have stylesheet A and I want to make a more specialised "subclass" called stylesheet B. which inherits most of the functions but overrides some templates.

the closest I can think of getting is to write template B including template A, and then put templates in B with the same "match" clause but with a higher priority than A. Unfortunately, a key feature would be to invoke the superclass method as part of the overridden method, and I can't see any way to do this.

TIA for Any ideas

Andy
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Andy Fish wrote:

the closest I can think of getting is to write template B including template A, and then put templates in B with the same "match" clause but with a higher priority than A. Unfortunately, a key feature would be to invoke the superclass method as part of the overridden method, and I can't see any way to do this.

Doesn't
<xsl:apply-imports />
do what you want?
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% the closest I can think of getting is to write template B including template % A, and then put templates in B with the same "match" clause but with a % higher priority than A. Unfortunately, a key feature would be to invoke the

xsl:import does this implicitly.

% superclass method as part of the overridden method, and I can't see any way % to do this.

Once you've used xsl:import, you can invoke the template from the imported stylesheet using xsl:apply-imports.

<!-- stylesheet A.xsl -->
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:eek:utput method='text'/>

<xsl:template match='A'>
<xsl:text>standard processing of A.</xsl:text>
</xsl:template>
</xsl:stylesheet>

<!-- stylesheet B.xsl -->
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<!-- this must come first! -->
<xsl:import href='A.xsl'/>

<xsl:template match='A'>
<xsl:text>Specialised processing of A, followed by </xsl:text> <xsl:apply-imports/> </xsl:template> </xsl:stylesheet>

<!-- A.xml -->
<A/>

of course in the real world I would use names like x.xsl and y.xsl. Anyway, if you process A.xml using A.xsl, you get this output

standard processing of A.

while if you process A.xml using B.xsl, you get this

Specialised processing of A, followed by standard processing of A.
 

David Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
I guess the latter remains true in XSLT 2.0, too.

yes although in 2 you can use next-match rather than apply-imports (with or without using xsl:import) this has rather different behaviour on edge cases.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top