Numbering line breaks in TEI documents
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Fri Jan 23, 2009 8:20 pm
Numbering line breaks in TEI documents
I'm sure that someone experienced can do this, but I'm stumped...
I have TEI documents in which line breaks from the original print versions need to be maintained. The first line break on each page is numbered, indicating where on the page the document began: (<lb n="16"/>). The rest of the line breaks are not numbered (i.e. have no attributes). With XSLT I am able to leave the numbered line breaks intact and insert the n attribute for all of the unnumbered ones, but I need for the content of this attribute to be 1 number higher than that of the immediately preceding lb element. I haven't found a way to do this.
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb/> confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb/> et molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb/> et arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan Beneitt, de Caors,
W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet, maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb/> Reula, e Johan de La Trena qui la carta enqueri, laquau W. Sancheir <lb/>escriuo.</p>
I have TEI documents in which line breaks from the original print versions need to be maintained. The first line break on each page is numbered, indicating where on the page the document began: (<lb n="16"/>). The rest of the line breaks are not numbered (i.e. have no attributes). With XSLT I am able to leave the numbered line breaks intact and insert the n attribute for all of the unnumbered ones, but I need for the content of this attribute to be 1 number higher than that of the immediately preceding lb element. I haven't found a way to do this.
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb/> confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb/> et molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb/> et arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan Beneitt, de Caors,
W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet, maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb/> Reula, e Johan de La Trena qui la carta enqueri, laquau W. Sancheir <lb/>escriuo.</p>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Numbering line breaks in TEI documents
Hi,
Start with a recursive copy template and add a rule that matches on lb elements without n attribute and output lb with n equal the preceding lb n value plus 1 as below:
Best Regards,
George
Start with a recursive copy template and add a rule that matches on lb elements without n attribute and output lb with n equal the preceding lb n value plus 1 as below:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<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="lb[not(@n)]">
<lb n="{1 + preceding-sibling::lb[1]/@n}"/>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
-
- Posts: 6
- Joined: Fri Jan 23, 2009 8:20 pm
Re: Numbering line breaks in TEI documents
For some reason this solution numbers the first relevant lb correctly (i.e., the first one following the lb that already has a numbered attribute), but all the succeeding ones show up with n="NaN"... What is that? In other words, I get the following:
<?xml version="1.0" encoding="utf-8"?>
<text>
<body>
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb n="5"/>
confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb n="NaN"/> et
molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb n="NaN"/> et
arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan
Beneitt, de Caors, W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet,
maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb n="2"/> Reula, e Johan de La Trena
qui la carta enqueri, laquau W. Sancheir <lb n="NaN"/>escriuo.</p>
</body>
</text>
<?xml version="1.0" encoding="utf-8"?>
<text>
<body>
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb n="5"/>
confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb n="NaN"/> et
molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb n="NaN"/> et
arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan
Beneitt, de Caors, W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet,
maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb n="2"/> Reula, e Johan de La Trena
qui la carta enqueri, laquau W. Sancheir <lb n="NaN"/>escriuo.</p>
</body>
</text>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Numbering line breaks in TEI documents
Right, sorry. Try the following:
on your sample
gives
Best Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<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="lb[not(@n)]">
<xsl:variable name="base" select="preceding-sibling::lb[@n][1]"/>
<lb n="{$base/@n + count(preceding-sibling::lb) - count($base/preceding-sibling::lb)}"/>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<text>
<body>
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb n="5"/>
confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb/> et
molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb/> et
arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan
Beneitt, de Caors, W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet,
maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb n="2"/> Reula, e Johan de La Trena
qui la carta enqueri, laquau W. Sancheir <lb/>escriuo.</p>
</body>
</text>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?><text>
<body>
<pb n="181"/>
<p><lb n="4"/> Conoguda causa sia que Sans deu Miralh, de La Reula, reconogo et <lb n="5"/>
confesset, per sin, en nom et en loc de la dona na Miramonda, sa molher,<lb n="6"/> et
molher qui fo d’en P. Calhau, que maiestre Johan de Forgeta, calonges <lb n="7"/> et
arcidiaque de Brulhes en la gleisa d’Agen, [...] n’Amanieus de Baliac, cauoirs, Johan
Beneitt, de Caors, W. Johan Langles, <pb n="182"/><lb n="1"/>qui esta au Castet,
maiestre Ramon d’Esidulh, Ramon de Lauizon, de La<lb n="2"/> Reula, e Johan de La Trena
qui la carta enqueri, laquau W. Sancheir <lb n="3"/>escriuo.</p>
</body>
</text>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service