473,763 Members | 9,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1365


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****@blueyon der.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:styleshe et version='1.0'
xmlns:xsl='http ://www.w3.org/1999/XSL/Transform'>

<xsl:output method='text'/>

<xsl:template match='A'>
<xsl:text>stand ard processing of A.</xsl:text>
</xsl:template>
</xsl:stylesheet>
<!-- stylesheet B.xsl -->
<xsl:styleshe et 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>Speci alised 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.c om
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****@blueyon der.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:styleshe et version='1.0'
xmlns:xsl='http ://www.w3.org/1999/XSL/Transform'>

<xsl:output method='text'/>

<xsl:template match='A'>
<xsl:text>stand ard processing of A.</xsl:text>
</xsl:template>
</xsl:stylesheet>
<!-- stylesheet B.xsl -->
<xsl:styleshe et 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>Speci alised 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.c om

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
2733
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 ANY window in VB? Thanks...
4
1849
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 something like : >>> t = Test('anAttributeValue', ) >>> t.anAttribute
2
1510
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 class, and, as long as I just use the write method, this works fine. But "print >>" doesn't behave as I want: class max_width_file(file): def write(self, txt): print "In max_width_file's write method." fout = max_width_file('foo.txt', 'w')
2
5161
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 class which is supposed to be a representation of a genome: class Genome(list): def __init__(self): list.__init__(self) self = ....
3
1695
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 parts computed in point()'s __init__ function with their values based on the arglist. I want to compute with point instances as though they were native complex numbers, but I want to be able to
11
3478
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
1548
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 discouraged and made it a bit harder to code (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebgen/html/bho.asp) Thank you for your help.
16
2077
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 it with inheritance, a kind of "dynamic subclassing", without subclassing the class, only this instance "b" ! In fact, i've got my instance "b", and another class "MoreMethods"
5
2531
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
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.