Re: Conflicting templates
- From: Joseph Kesselman <keshlam-nospam@xxxxxxxxxxx>
- Date: Tue, 06 Mar 2007 11:16:23 -0500
patrik.nyman@xxxxxxxxxxxx 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="substring-before($w,'|')"/>
<xsl:variable name="cdr"
select="substring-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:otherwise>
<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|nated">Hyphenated</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>Hyphe</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 <it> and <choose> elements
are not working. Can anyone help me out?
Thanks a lot
/Patrik Nyman
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
.
- Follow-Ups:
- Re: Conflicting templates
- From: patrik . nyman
- Re: Conflicting templates
- From: Joseph Kesselman
- Re: Conflicting templates
- References:
- Conflicting templates
- From: patrik . nyman
- Conflicting templates
- Prev by Date: Re: Test suite for XPath 1.0?
- Next by Date: Re: Conflicting templates
- Previous by thread: Conflicting templates
- Next by thread: Re: Conflicting templates
- Index(es):
Relevant Pages
|