line break and hyphenation

P

patrik.nyman

I'm doing markup of some original texts, and want
to be able too optionally keep the line breaks of
the original. But sometimes a word is hyphenated
at a line break. At TEI-L I found the proposition
to encode such cases as

<reg orig="hyphe|nated">hyphenated</reg>

This seems good because the word is availabe for
greping etc. My problem is, how do I write an xslt
template to deal with this? I want to be able to
get both 'hyphe-<br/>nated' and 'hyphenated' as
output. Is there someone who can help me?

/Patrik Nyman
 
P

p.lepin

I'm doing markup of some original texts, and want
to be able too optionally keep the line breaks of
the original. But sometimes a word is hyphenated
at a line break. At TEI-L I found the proposition
to encode such cases as

<reg orig="hyphe|nated">hyphenated</reg>

This seems good because the word is availabe for
greping etc. My problem is, how do I write an xslt
template to deal with this?

What have you tried?
I want to be able to get both 'hyphe-<br/>nated'

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="reg">
<xsl:apply-templates select="@orig"/>
</xsl:template>
<xsl:template match="reg/@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:eek:therwise>
<xsl:value-of select="$w"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>
and 'hyphenated' as output.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="reg">
<xsl:apply-templates select="node()"/>
</xsl:template>
</xsl:stylesheet>
 
P

patrik.nyman

Hello again, Pavel!

What have you tried?

It was too lame to show in public...

Your code works brilliantly (of course). Thanks a lot
for helping me out again, I really appreciate it.

Merry Christmas,
/Patrik Nyman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top