[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: n-value of preceding lb-element

Subject: Re: n-value of preceding lb-element
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Mon, 13 Aug 2001 14:55:15 -0400
n value
[Ingo Mittendorf]

> What I want to generate from the example text below is this table (no
> more, no less):
>
> LINE ERROR      CORRECTION
> 1 sayed      said
> 2 tearfull   tearful
> 2 four       for
> 5 milions    millions
>

Here's a stylesheet that produces your output from your xml example.  First,
the output:

--------------------------------------------------
LINE ERROR CORRECTION

[line 1]  sayed  said.

[line 2] tearfull  tearful.

[line 2] four  for.

[line 5] milions  millions.
-------------------------------------------------

The hardest part is control of line breaks in text output , which can be
different for different xslt processors.  Some of the slightly strange
formatting of the stylesheet is there to produce the right text formatting
(including the periods (".") at the ends of the lines).  If you wanted to
get HTML tables, they wouldn't be necessary.   If you run this stylesheet
and the output formatting is different, it may be because some lines got
refomatted by your email client.  I've tried to keep them short enough that
this wouldn't happen, but I can't be sure.

Of course, you could change the "[line 2]" format to just "2" - I've left it
this way for readability.

I'm not absolutely sure I have handled all the possible cases, but it should
be close enough for you to evolve if needed.

The key points are

1) Line breaks can be children of either a <p> or an <s> element, so there
is a template with a different mode for each case.

2) For each <lb> within an <s> element, the lb template looks to see if
there is a following sibling <corr> element.  If not, no output is
generated.

3) For each <corr> element, the template checks to see if the immediately
preceeding sibling was an <lb>.  If not, it finds the line break number of
the first preceeding <lb> it finds within the same <s> element, and outputs
that for the line number.  Otherwise, there would be no way to output the
line number.

Here's the stylesheet:

---------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text' encoding='iso-8859-1'/>

<xsl:template match="/example">
<results>
LINE ERROR CORRECTION
<xsl:apply-templates select='p'/>
</results>
</xsl:template>

<xsl:template match='p'>
 <xsl:apply-templates select='lb|s' mode='in_p'/>
</xsl:template>

<xsl:template match='s' mode='in_p'>
 <xsl:apply-templates select='lb|corr' mode='in_s'/>
</xsl:template>

<xsl:template match='s' mode='in_s'>
 <xsl:apply-templates select='lb|corr' mode='in_s'/>
</xsl:template>

<xsl:template match='corr' mode='in_s'>
 <xsl:variable name='lastLB'
    select='name(preceding-sibling::*[1])="lb"'/>
 <xsl:variable name='lastn'
    select='preceding-sibling::lb/@n'/>
 <xsl:if test='not($lastLB) and $lastn>0'
    >[line <xsl:value-of select='$lastn'/>]</xsl:if
 >&#32;<xsl:value-of select='@sic'/> &#32;<xsl:value-of select='.'/>.
</xsl:template>

<xsl:template match='lb' mode='in_p'
 ><xsl:variable name='n' select='@n'
 />[line <xsl:value-of select='$n'/>] <xsl:apply-templates
     select='corr' mode='in_s'/>
</xsl:template>

<xsl:template match='lb' mode='in_s'
 ><xsl:if test='name(following-sibling::*)="corr"'
  >[line <xsl:value-of select='@n'/>]</xsl:if></xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.