473,408 Members | 2,450 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,408 software developers and data experts.

Conditionalized typesetting

I have several texts that are to be typeset with minor
differences. I do not want to duplicate any xsl-code,
so I'm trying to find a way to reuse code, but have
changes implemented when applicable. One approach is
of course to have a specific xsl-file for every text,
and import the more general file into it. Another
approach I have thought of, is to have just one xsl-file
and conditionalize it. In the xml-files I have something
like <text work="kerner">, <text work="kerner">, etc.,
and in the xsl-file templates like

<xsl:template match="pb">
<xsl:choose>
<xsl:when test="//@verk='kerner'">
<p class="pagina"><xsl:value-of select="@n"/></p>
</xsl:when>
<xsl:when test="//@verk='kalm'">
<p class="pagina">( <xsl:value-of select="@n"/)</p>
</xsl:when>
</xsl:choose>
</xsl:template>

This works fine, but I'd be glad to get some input on
which method is preferrable, or if there might be other
ways to do this. What are your experiences?

Jan 15 '07 #1
4 1862
pa**********@orient.su.se wrote:
I have several texts that are to be typeset with minor
differences. I do not want to duplicate any xsl-code,
so I'm trying to find a way to reuse code, but have
changes implemented when applicable. One approach is
of course to have a specific xsl-file for every text,
and import the more general file into it. Another
approach I have thought of, is to have just one xsl-file
and conditionalize it. In the xml-files I have something
like <text work="kerner">, <text work="kerner">, etc.,
and in the xsl-file templates like

<xsl:template match="pb">
<xsl:choose>
<xsl:when test="//@verk='kerner'">
<p class="pagina"><xsl:value-of select="@n"/></p>
</xsl:when>
<xsl:when test="//@verk='kalm'">
<p class="pagina">( <xsl:value-of select="@n"/)</p>
</xsl:when>
</xsl:choose>
</xsl:template>

This works fine, but I'd be glad to get some input on
which method is preferrable, or if there might be other
ways to do this. What are your experiences?
the tests starting with // search the entire document looking for an
attribute of that name, so they are fairly expensive. You may be better
to move them to a global variable (although probably your xslt system's
optimiser will do that anyway). Although I suspect that you meant to
test the attribute o the current pb element ? or the document element
?if so the test wants to be test="@work='kerner'] or
test="/*/@work='kerner']

whenever there is a template that just consists of a choose it's often
more convenient (and perhaps more efficient) to write it as multiple
templates

<xsl:template match="pb[@verk='kerner']">
<p class="pagina"><xsl:value-of select="@n"/></p>
</xsl:template>

<xsl:template match="pb[@verk='kalm']">
<p class="pagina">( <xsl:value-of select="@n"/)</p>
</xsl:template>

David
Jan 16 '07 #2
David Carlisle wrote:
the tests starting with // search the entire document looking for an
attribute of that name, so they are fairly expensive. You may be better
to move them to a global variable (although probably your xslt system's
optimiser will do that anyway). Although I suspect that you meant to
test the attribute o the current pb element ? or the document element
?if so the test wants to be test="@work='kerner'] or
test="/*/@work='kerner']
Thanks for this remark. Yes, I want to test the document element,
so the /*/@work='kerner' construction would be fine, since there are
several
templates that should be conditionalized. Should I take it that you
think this
is a good method for accomplishing my goal? Or are there any drawbacks?

Or perhaps a better way to do it?

/Patrik Nyman

Jan 16 '07 #3
pa**********@orient.su.se wrote:
templates that should be conditionalized. Should I take it that you
think this
is a good method for accomplishing my goal? Or are there any drawbacks?

Or perhaps a better way to do it?

/Patrik Nyman
it's fine, although I'd use multiple templates rather than an xs:choose.
it looks neater and can be more efficient.

<xsl:template match="*">
<xsl:choose>
<xsl:when test="self::aaa">...
<xsl:when test="self::bbb">...
....

is more or less the same as

<xsl:template match="aaa">...
<xsl:template match="bbb">...

but in the first case, your system probably has to do a linear search of
the node against each test so expected time proportional to the number
of branches.

in the second case the system probably hashes the templates against the
match name at compile time so at run time doesn't have to test every
template.

this is of course all highly dependent on the processor, the processor
could in theory rewrite either form to the same internal expresssion, or
might not hash the templates or...

unless you have hundreds of choices in the choose it probably makes no
observable time difference, I think main attraction of having more
templates and less choose blocks is that it's just more the "xsl way" :-)
Jan 16 '07 #4

David Carlisle wrote:
pa**********@orient.su.se wrote:
templates that should be conditionalized. Should I take it that you
think this
is a good method for accomplishing my goal? Or are there any drawbacks?

Or perhaps a better way to do it?

/Patrik Nyman

it's fine, although I'd use multiple templates rather than an xs:choose.
it looks neater and can be more efficient.

<xsl:template match="*">
<xsl:choose>
<xsl:when test="self::aaa">...
<xsl:when test="self::bbb">...
...

is more or less the same as

<xsl:template match="aaa">...
<xsl:template match="bbb">...

but in the first case, your system probably has to do a linear search of
the node against each test so expected time proportional to the number
of branches.

in the second case the system probably hashes the templates against the
match name at compile time so at run time doesn't have to test every
template.

this is of course all highly dependent on the processor, the processor
could in theory rewrite either form to the same internal expresssion, or
might not hash the templates or...

unless you have hundreds of choices in the choose it probably makes no
observable time difference, I think main attraction of having more
templates and less choose blocks is that it's just more the "xsl way" :-)
Thanks a lot for these clarifications.

/Patrik Nyman

Jan 18 '07 #5

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

Similar topics

21
by: James Moe | last post by:
Hello, I just joined this group and saw the discussion "What do you think of resizing 1em to 10px?" I am somewhat confused by what y'all think should be used as a reference size. I was surprised...
10
by: Justin Barrett | last post by:
Hi I'm currently doing a project in my free time. One problem I ran into is that things like short, int, and long all have different meanings as to size on different platforms. In this program...
6
by: Roger Shrubber | last post by:
I know HTML was never designed to be WYSIWYG, but with CSS, there is much greater control over coordinates and dimensions. So I would expect that a specific piece of text, with a specific font,...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
1
by: mats.broberg | last post by:
Dear all, I'm having a scientific text translated into the majority of western and eastern European languages* and have provided a small leaflet with typesetting rules for the translators. Some...
28
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
1
by: vbfoobar | last post by:
Hello, I have HTML input to which I apply some changes. Feature 1: ======= I want to tranform all the text, but if the text is inside an "a href" tag, I want to leave the text as it is. ...
1
by: jonathanellis | last post by:
Hello: I am having a problem with a web site that i built not showing up properly in IE6. I haven't tested it in IE7, but I have tested it in Firefox and Safari. Both Firefox and Safari show the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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.