473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

subclassing in XSLT

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


Jul 20 '05 #1
5 1351


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?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
In article <dH*********************@news-text.cableinet.net>,
Andy Fish <aj****@blueyonder.co.uk> 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

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:output 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.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #3
>
xsl:import does this implicitly.


D'oh!

Thanks guys - I hadn't noticed that one before.
Jul 20 '05 #4
Just a note that in XSLT 1.0 xsl:apply-imports cannot be passed any
parameters.

There are also some nasty surprises with import precedence -- e.g. see what
Jeni Tennison had to say at:

http://www.biglist.com/lists/xsl-lis.../msg01135.html

I guess the latter remains true in XSLT 2.0, too.

Cheers,

Dimitre Novatchev.

"Patrick TJ McPhee" <pt**@interlog.com> wrote in message
news:2q************@uni-berlin.de...
In article <dH*********************@news-text.cableinet.net>,
Andy Fish <aj****@blueyonder.co.uk> 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

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:output 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.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com

Jul 20 '05 #5
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
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: WhiteRavenEye | last post by:
Why can't I subclass any window except mine in VB? Do I have to write dll for this? I've tried to subclass it with SetWindowLong but without success... Does anyone know how to subclass window...
4
by: GrelEns | last post by:
hello, i wonder if this possible to subclass a list or a tuple and add more attributes ? also does someone have a link to how well define is own iterable object ? what i was expecting was...
2
by: David Vaughan | last post by:
I'm using v2.3, and trying to write to text files, but with a maximum line length. So, if a line is getting too long, a suitable ' ' character is replaced by a new line. I'm subclassing the file...
2
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this...
3
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
11
by: Brent | last post by:
I'd like to subclass the built-in str type. For example: -- class MyString(str): def __init__(self, txt, data): super(MyString,self).__init__(txt) self.data = data
3
by: alotcode | last post by:
Hello: What is 'interprocess subclassing'? To give more context, I am writing in reference to the following remark: With the advent of the Microsoft Win32 API, interprocess subclassing was...
16
by: manatlan | last post by:
I've got an instance of a class, ex : b=gtk.Button() I'd like to add methods and attributes to my instance "b". I know it's possible by hacking "b" with setattr() methods. But i'd like to do...
5
by: Ray | last post by:
Hi all, I am thinking of subclassing the standard string class so I can do something like: mystring str; .... str.toLower (); A quick search on this newsgroup has found messages by others
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.