473,666 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conflicting templates

I have this templates to mark up hyphenation over line breaks:

<xsl:template match="reg[@type='hyp']">
<xsl:apply-templates select="@orig"/>
</xsl:template>

<xsl:template match="reg[@type='hyp']/@orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

<xsl:template name="html-hyphens">
<xsl:param name="w" select="."/>
<xsl:variable name="car"
select="substri ng-before($w,'|')"/>
<xsl:variable name="cdr"
select="substri ng-after($w,'|')"/>
<xsl:choose>
<xsl:when test="$cdr">
<xsl:value-of select="concat( $car,'-')"/>
<br/>
<xsl:call-template name="html-hyphens">
<xsl:with-param name="w" select="$cdr"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$w"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

I also have this simple template for italic text:

<xsl:template match ="it">
<i><xsl:apply-templates/></i>
</xsl:template>

This works fine if I write something like:

<it><reg type="hyp" orig="Hyphe|nat ed">Hyphenate d</reg></it>

Now I can choose if I want to preserve linebreaks or not.
But as it happens, in some of the texts I'm working on,
sometimes ony part of the word is in italics (or formatted
some other way), like <it>Hyphe</it>nated, and since I
can't do

<reg type="hyp" orig="<it>Hyphe </it>|nated"><it> Hyphe</it>nated</
reg>

I must write something like:

<choice type="hyp">
<orig><it>Hyphe </it>|nated</orig>
<reg><it>Hyph e</it>nated</reg>
</choice>

So for this I added the following templates:

<xsl:template match="choice[@type='hyp']">
<xsl:apply-templates select="./orig"/>
</xsl:template>

<xsl:template match="choice[@type='hyp']/orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

But the combination of the <itand <chooseelemen ts
are not working. Can anyone help me out?

Thanks a lot
/Patrik Nyman

Mar 6 '07 #1
9 1632
pa**********@or ient.su.se wrote:
I have this templates to mark up hyphenation over line breaks:
I'll try to look at this in more detail later, but... Y'know, this is
the sort of task that I would suggest handling in the redering engine,
rather than at the XML level. The renderer is the level which knows
where line breaks are going to have to be inserted, and is traditionally
where hyphenation is done as a result. That's generally driven by a
dictionary, though it could certainly take advantage of hints in the source.


>
<xsl:template match="reg[@type='hyp']">
<xsl:apply-templates select="@orig"/>
</xsl:template>

<xsl:template match="reg[@type='hyp']/@orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

<xsl:template name="html-hyphens">
<xsl:param name="w" select="."/>
<xsl:variable name="car"
select="substri ng-before($w,'|')"/>
<xsl:variable name="cdr"
select="substri ng-after($w,'|')"/>
<xsl:choose>
<xsl:when test="$cdr">
<xsl:value-of select="concat( $car,'-')"/>
<br/>
<xsl:call-template name="html-hyphens">
<xsl:with-param name="w" select="$cdr"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$w"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

I also have this simple template for italic text:

<xsl:template match ="it">
<i><xsl:apply-templates/></i>
</xsl:template>

This works fine if I write something like:

<it><reg type="hyp" orig="Hyphe|nat ed">Hyphenate d</reg></it>

Now I can choose if I want to preserve linebreaks or not.
But as it happens, in some of the texts I'm working on,
sometimes ony part of the word is in italics (or formatted
some other way), like <it>Hyphe</it>nated, and since I
can't do

<reg type="hyp" orig="<it>Hyphe </it>|nated"><it> Hyphe</it>nated</
reg>

I must write something like:

<choice type="hyp">
<orig><it>Hyphe </it>|nated</orig>
<reg><it>Hyph e</it>nated</reg>
</choice>

So for this I added the following templates:

<xsl:template match="choice[@type='hyp']">
<xsl:apply-templates select="./orig"/>
</xsl:template>

<xsl:template match="choice[@type='hyp']/orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

But the combination of the <itand <chooseelemen ts
are not working. Can anyone help me out?

Thanks a lot
/Patrik Nyman

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 6 '07 #2
(Apologies for not trimming the quote.)
Mar 6 '07 #3
On 6 Mar, 16:16, Joseph Kesselman <keshlam-nos...@comcast. netwrote:
patrik.ny...@or ient.su.se wrote:
I have this templates to mark up hyphenation over line breaks:

I'll try to look at this in more detail later, but... Y'know, this is
the sort of task that I would suggest handling in the redering engine,
rather than at the XML level. The renderer is the level which knows
where line breaks are going to have to be inserted, and is traditionally
where hyphenation is done as a result. That's generally driven by a
dictionary, though it could certainly take advantage of hints in the source.
I fully agree, but in this particular case, I'm doing markup of
pre-existing texts (from 18th century books) and need to
be able to make different versions, one that preserves the
original line breaks, and one where the rendering engine
(i.e., LaTeX) decides where to break lines. Hence
my markup, and my problem!

Mar 6 '07 #4
pa**********@or ient.su.se wrote:
I fully agree, but in this particular case, I'm doing markup of
pre-existing texts (from 18th century books) and need to
be able to make different versions, one that preserves the
original line breaks, and one where the rendering engine
(i.e., LaTeX) decides where to break lines. Hence
my markup, and my problem!
Why dont you use one of the existing packages
for scholarly critical editions ?

http://www.ucl.ac.uk/~ucgadkw/edmac/index.html
http://ednotes.sty.de.vu/
Mar 6 '07 #5
Jürgen Kahrs wrote:
http://ednotes.sty.de.vu/
Hm. ledmac is LaTeX-based, and I know folks have experiemented with XML
front-end syntaxes for LaTeX...

But I'm not going to dismiss this out of hand; sometimes inventing a new
markup is legitimate in order to get the behaviors you want. (After all
that's how edmac/ledmac started). So let's ignore the question of why
two alternate renderings are desired think about how we achieve them. My
instinct says stylesheet modes, but I want to look at the question again.

I'm a bit distracted right now; I'll try to get back to this later.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 6 '07 #6
pa**********@or ient.su.se wrote:
But the combination of the <itand <chooseelemen ts
are not working.
One obvious question: Do you have templates for <origand <reg>? Or at
least an explicit identity template which is catching these? If not,
you'll get XSLT's built-in default template, which just returns the
contained text -- and as a result you'll lose any markup below that
point, specifically the <it>.
("Not working" isn't a very useful description. It'd help if you could
post a minimal example of an input document, and a complete stylesheet
that contains just enough logic to demonstrate what you're doing and
what isn't working. Runnable examples are easier to review/debug than
out-of-context fragments, because they make obvious the answers to
questions like the one I just raised.)
Another obvious alternative would be to turn the markup inside out:
<it><reg type="hyp" orig="Hyphe|">H yphe</reg></it>nated

Or to reconsider the whole thing and use something more like
<it>Hyphe<hyp/></it>nated
and then have <hyp/either render as your visible hyphen or as nothing
depending on whether people want to see it.

(If your markup is making life complicated, maybe it's the wrong markup...)

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 6 '07 #7
On 6 Mar, 22:27, Joseph Kesselman <keshlam-nos...@comcast. netwrote:
patrik.ny...@or ient.su.se wrote:
But the combination of the <itand <chooseelemen ts
are not working.
("Not working" isn't a very useful description. It'd help if you could
post a minimal example of an input document, and a complete stylesheet
that contains just enough logic to demonstrate what you're doing and
what isn't working.
Of course, se bottom of this post
Another obvious alternative would be to turn the markup inside out:
<it><reg type="hyp" orig="Hyphe|">H yphe</reg></it>nated

Or to reconsider the whole thing and use something more like
<it>Hyphe<hyp/></it>nated
and then have <hyp/either render as your visible hyphen or as nothing
depending on whether people want to see it.
Originally, I wanted the <reg type="hyp" orig="Hyphe|
nated">Hyphenat ed</reg>
markup so the hyphenated word would be avaliable for greping and
database
searches, etc. But now I realize if I'm gonna stick <it>'s in there
it
can't be greped anyway... So maybe I need something like

<choice type="hyp">
<orig><it>Hyphe </it>|nated</orig>
<reg><it>Hyph e</it>nated</reg>
<plain>Hyphenat ed</plain>
</choice>

And then it starts getting out of hand...

Anyway, it would be interesting if my example could be made to work.
It would be useful in other situations as well. So here's the example.
Nr 1 and 4 works as expected, nr 2 gives no italics, nr 3 gives no
output at all.

%<--------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="applicati on/xml" href="./hyp.xsl"?>

<!DOCTYPE TEST>

<TEST>

<it><reg type="hyp" orig="Hyphe|nat ed-1">Hyphenate d-1</reg></it>

<choice type="hyp">
<orig><it>Hyphe </it>|nated-2</orig>
<reg><it>Hyph e</it>nated-2</reg>
</choice>

<choice type="hyp">
<it><orig>Hyphe |nated-3</orig></it>
<it><reg>Hyphen ated-3</reg></it>
</choice>

<it>
<choice type="hyp">
<orig>Hyphe|nat ed-4</orig>
<reg>Hyphenat ed-4</reg>
</choice>
</it>

</TEST>

%<--------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:xd="http://www.pnp-software.com/XSLTdoc">

<xsl:output method="html"/>

<xsl:template match="@*|node( )">
<xsl:copy>
<xsl:apply-templates select="@*|node ()"/>
</xsl:copy>
</xsl:template>

<xsl:template match ="it">
<i><xsl:apply-templates/></i>
</xsl:template>

<xsl:template match="reg[@type='hyp']">
<xsl:apply-templates select="@orig"/>
</xsl:template>

<xsl:template match="reg[@type='hyp']/@orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

<xsl:template match="orig">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="reg">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="choice[@type='hyp']">
<xsl:apply-templates select="./orig"/>
</xsl:template>

<xsl:template match="choice[@type='hyp']/orig">
<xsl:call-template name="html-hyphens"/>
</xsl:template>

<xsl:template name="html-hyphens">
<xsl:param name="w" select="."/>
<xsl:variable name="car"
select="substri ng-before($w,'|')"/>
<xsl:variable name="cdr"
select="substri ng-after($w,'|')"/>
<xsl:choose>
<xsl:when test="$cdr">
<xsl:value-of select="concat( $car,'-')"/>
<br/>
<xsl:call-template name="html-hyphens">
<xsl:with-param name="w" select="$cdr"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="$w"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

%<-------------------------------------------------------------

/Patrik Nyman

Mar 7 '07 #8
nr 2 gives no italics, nr 3 gives no output at all.

OK, let's look at it.

#2:
"choice[@type='hyp']" applies templates against its <origchild.
That's matched by the template for "choice[@type='hyp']/orig".
This hands off to named template "html-hyphens" with no parameter.
The parameter's default value is ., which will be the <origelement.
All that's done with the parameter is to take its string value.
String value of that <origis the concatenation of its text
descendants; the <itis correctly ignored.
#3 is even more obvious: You're explicitly processing the <origchild.
There is no <origchild; the child elements are both <itelements.
You're getting exactly what you asked for. If it isn't what you wanted,
slow down and think about exactly what you're trying to recognize at
each stage and what you want to do with it. XSLT is a programming
language; it does only and exactly what you tell it to do.

Coming up with a version which handles all four cases is left as an
exercise for the student. Hint: If you want to recognize the two options
and select between them no matter how deeply buried they are in other
markup, you're going to have to select which subtree to process based
upon its descendants.

Personally, I still think you're needlessly complicating the problem.
Were I in your shoes I'd be fighting to get the markup designed from
first principles in a form that's actually amenable to straightforward
processing rather than trying to tolerate sloppy usage. You should be
able to achieve that while still retaining all the historical
information, if you take the time to structure your descriptive
hierarchies correctly.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 8 '07 #9
On 8 Mar, 02:59, Joe Kesselman <keshlam-nos...@comcast. netwrote:
nr 2 gives no italics, nr 3 gives no output at all.

OK, let's look at it.
Thanks for your input. I think your hints will help me solve
the problem.

/Patrik

Mar 8 '07 #10

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

Similar topics

0
1789
by: frasfan | last post by:
Hi, I am having a problem with the validator controls in VB.net conflicting with the javascript I am using to confirm whether or not the user wants to submit the page. Here is the situation: I am having the user edit a page with text boxes populated from a query against a SQL Server database. When the user clicks on "Save", the information currently contained in the text boxes will be saved to the database. I am using the following code...
5
2528
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element of the currently matched element in the template, so that XPath expressions inside would be relative to that node? Specifically, I want to do this, in order to be able to issue xsl:call-template to apply some templates to some
22
2177
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding solutions which are overly specific),
2
3978
by: humble04 | last post by:
Hi, I am compiling a collection of C++ code. Most of them are using the new format #include <iostream>. I think all of them because I failed at finding out which header file uses the old format #include <iostream.h>. However, I met the following error messages. "/usr/vacpp/include/iostream.h", line 74.7: 1540-0400 (S) "class ostream" has a conflicting declaration "../include/myfile.h", line 7.1: 1540-0424 (I) "ostream" is declared on
3
5583
by: Ton van den Heuvel | last post by:
Hi all, why does the following code not compile, and fail with: qed.cpp: In instantiation of `B<Foo*>': qed.cpp:40: instantiated from here qed.cpp:29: error: conflicting return type specified for `const T B<T>::Test() const ' qed.cpp:14: error: overriding `virtual const Foo* A::Test() const'
7
2610
by: Thiru | last post by:
I am writing an application that interacts with Oracle and Teradata. In order to create the executable, I need to link various Oracle and Teradata libraries. I found out that when I link the Oracle and Teradata libraries together, the Teradata API functions are not working properly. My assumption is that these libraries are sharing identical function names and parameter lists and hence the conflicts are causing the problem. Is my...
28
2628
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the executable size. This should not cause any performance issue. So, is it safe to say that if I can offered to have bigger image size I can go ahead and use Templates with out worrying about any other issues?
1
1922
by: helraizer1 | last post by:
Hi folks, I have an image based shoutbox which I am currently implementing emoticons onto. I have a way now for the emoticons to appear where the :D or =) etc. is on the image, but for some reason they seem to be conflicting. I shall try to explain. chatbox.php - only necessary code shown $grins = array('=D', "=d", ":d", ":D"); foreach ($grins as $grin) {
12
9121
by: Michael.Z | last post by:
Anyone who can help: Given a Table.h file I am writing a Table.c file. I keep getting the compile error: previous declaration of Table was here / conflicting types for I think the problem was the result of two pieces of code. First: typedef struct Table; /* in Table.c*/
0
8363
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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
8787
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8645
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
6203
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
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
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.