TEI XSL:FO/HTML

J

JLP

Hello,

I have a couple of hundred books in TEI based XML. I want to output
html and pdf documents. I started building my own style sheets to do
this and I ran into a problem with footnotes. Many of my documents
have longer footnotes so I did the following:

<p>Text...text...text...<note><p>footnote body.</p><p>The next
paragraph in the footnote</p></note></p>

Now I have the xsl:

<xsl:template name="div">
<xsl:for-each select="./div">
<h1>
<xsl:value-of select="head"/>
</h1>
<xsl:for-each select="p">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

and I get the text inside the note. How can I process this properly?

I think I'd like to leave the footnotes in my source alone, unless
there is a truly better way to do this.

Thanks in advance!

Jeremy
 
D

David Carlisle

Hello,

I have a couple of hundred books in TEI based XML. I want to output
html and pdf documents. I started building my own style sheets to do
this

You know there is already a fairly extensive set of TEI stylesheets for
HTML and for FO?

http://www.tei-c.org/Stylesheets/teixsl.html

However there's no reason not to build your own as well, so:
and I ran into a problem with footnotes. Many of my documents
have longer footnotes so I did the following:

<p>Text...text...text...<note><p>footnote body.</p><p>The next
paragraph in the footnote</p></note></p>

Now I have the xsl:

<xsl:template name="div">
<xsl:for-each select="./div">

This line is rather odd, it means that for each div you
ignore all its text and element children exept immediately nested divs,.
so given
<div>
<p>zz</p>
<div>
<p>xxx</p>
</div>
</div>

when the template matches on the outer div you ignore the zz paragraph
and just process the inner div.

<h1>
<xsl:value-of select="head"/>

Using value-of here rather than apply-templates means that you get the
the string value of the head but means that you will not process any
nested markup within the head.

<xsl:for-each select="p">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
again I don't think you want for-each and value-of in the above.
</xsl:for-each>
</xsl:template>

and I get the text inside the note. How can I process this properly?

I think I'd like to leave the footnotes in my source alone, unless
there is a truly better way to do this.

Thanks in advance!

Jeremy


Something like the following should make a html div out of a TEI div,
with an html heading, and all children processed, note elements just
make a superscripted number, and at the end of the div, if there were
any notes it makes a list of the numbers and note texts (untested)

<xsl:template match="div">
<div>
<xsl:apply-templates select="head"/>
<xsl:apply-templates select="node()[not(self::head)]"/>
<xsl:if test=".//note">
<hr/>
<dl>
<xsl:for-each select=".//note">
<dt><xsl:number level="any"/></dt>
<dd><xsl:apply-templates/></dd>
</xsl:for-each>
</dl>
</xsl:if>
</div>
</xsl:template>

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

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

<xsl:template match="note">
<sup><xsl:number level="any"/></sup>
</xsl:template>
 
J

JLP

David,

Thank you for your response!

I did have some success with this XSL. It seems to be doing much
better now. I'm still a bit stuck on exactly what:

<xsl:apply-templates select="node()[not(self::head)]"/>

does.

node() is that some form of boolean function? I was not able to find
it in the XSLT functions reference or the XPath functions. Is this
selecting all elements except "node()[not(self::head)]"?

The results of what you posted are pretty good except that I get two
sets of footnotes. I suspect that line above, hence the questions.

As you probably have guessed, I'm new to XSL. Your help is greatly
appreciated!

As for writing my own XSL/XSL:FO for TEI, the style sheets that are
available for HTML are decent, I just wanted to learn XSL/XSL:FO. What
I really want is XSL:FO, but I thought XSL would be a good starting
point. The TEI XSL:FO style sheets use PassiveTeX. I've never quite
understood how they are supposed to work physically. Logically it
seems you have to have some software installed (jadeTeX?) to process
them appropriately. I never found a good how to on configuration. At
any rate, I will probably want to customize it for my own needs
anyway. I think it is better for me to write my own.

So far this seems to be a component driven process. I mean I can write
a snippet of XSL for div elements and then use it in other places
which is nice. Are there any good references on design strategies for
this kind of thing? Not just what the XSL elements are, but how to put
them together and how to do things efficiently?

Thanks again to everyone!

Jeremy

David Carlisle said:
Hello,

I have a couple of hundred books in TEI based XML. I want to output
html and pdf documents. I started building my own style sheets to do
this

You know there is already a fairly extensive set of TEI stylesheets for
HTML and for FO?

http://www.tei-c.org/Stylesheets/teixsl.html

However there's no reason not to build your own as well, so:
and I ran into a problem with footnotes. Many of my documents
have longer footnotes so I did the following:

<p>Text...text...text...<note><p>footnote body.</p><p>The next
paragraph in the footnote</p></note></p>

Now I have the xsl:

<xsl:template name="div">
<xsl:for-each select="./div">

This line is rather odd, it means that for each div you
ignore all its text and element children exept immediately nested divs,.
so given
<div>
<p>zz</p>
<div>
<p>xxx</p>
</div>
</div>

when the template matches on the outer div you ignore the zz paragraph
and just process the inner div.

<h1>
<xsl:value-of select="head"/>

Using value-of here rather than apply-templates means that you get the
the string value of the head but means that you will not process any
nested markup within the head.

<xsl:for-each select="p">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
again I don't think you want for-each and value-of in the above.
</xsl:for-each>
</xsl:template>

and I get the text inside the note. How can I process this properly?

I think I'd like to leave the footnotes in my source alone, unless
there is a truly better way to do this.

Thanks in advance!

Jeremy


Something like the following should make a html div out of a TEI div,
with an html heading, and all children processed, note elements just
make a superscripted number, and at the end of the div, if there were
any notes it makes a list of the numbers and note texts (untested)

<xsl:template match="div">
<div>
<xsl:apply-templates select="head"/>
<xsl:apply-templates select="node()[not(self::head)]"/>
<xsl:if test=".//note">
<hr/>
<dl>
<xsl:for-each select=".//note">
<dt><xsl:number level="any"/></dt>
<dd><xsl:apply-templates/></dd>
</xsl:for-each>
</dl>
</xsl:if>
</div>
</xsl:template>

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

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

<xsl:template match="note">
<sup><xsl:number level="any"/></sup>
</xsl:template>
 
D

David Carlisle

<xsl:apply-templates select="node()[not(self::head)]"/>

does.

node() is that some form of boolean function?

Not really it's a node test (along with with text() comment() and
processing-instruction()) it selects any node (* in that position
would just match element nodes. In particular if you do
<xsl:apply-templates select="node()"/>
or equivalently
<xsl:apply-templates/>
templates get applied to child text as well as child element nodes.

Obviously text nodes are never head elements so the
node()[not(self::head)]
is the same as
text()|*[not(self::head)]
(well actually it's the same as

comment()|processing-instruction()|text()|*[not(self::head)]

I was not able to find
it in the XSLT functions reference or the XPath functions. Is this
selecting all elements except "node()[not(self::head)]"?

It's in xpath.

As for writing my own XSL/XSL:FO for TEI, the style sheets that are
available for HTML are decent, I just wanted to learn XSL/XSL:FO. What
I really want is XSL:FO, but I thought XSL would be a good starting
point.

Yes that's a good idea and you'll learn more rolling your own, although
in the end you may find that to handle complicated tei books customising
sebastian's efforts might be quicker if you just want to get the job
done rather than rolling your own. For TEI (and the conceptually
similar docbook stylesheets) a lot of years fine tuning edge cases have
gone in to the stylesheets, so for any given document it's often simpler
to write your own focussed stylesheet, but to produce something that
can handle a large range of documents within the specific dtd, using a
"standard" stylesheet has advantages.


The TEI XSL:FO style sheets use PassiveTeX.

Not really, The fO files they generate can be used by any FO renderer
(FOP, renderx, ....). Passivetex was generated at the same time by the
same person (except for the low level xml parsing part which he
tricked someone else in to writing) but the stylesheets produce standard
FO (in general, they may use a few extension elements for specific jobs,
I haven't looked recently)

Logically it
seems you have to have some software installed (jadeTeX?) to process
them appropriately.

You need tex, jadetex is something else, similar to passivetex but
working with dsssl rather than xsl dsssl being the older style language
for sgml rather than xml documents (Sebastian and I have been in this
game too long:) If you are not already a tex user (why not:) to be
honest I wouldn't start with passivetex I'd start with fop if you are
looking for a free FO engine as that is by far the most commonly used
free one so you'll get more "community" support using that.

So far this seems to be a component driven process. I mean I can write
a snippet of XSL for div elements and then use it in other places
which is nice. Are there any good references on design strategies for
this kind of thing? Not just what the XSL elements are, but how to put
them together and how to do things efficiently?


xsl-list has a good faq site, jeni's site is also good

http://www.dpawson.co.uk/xsl/xslfaq.html
http://www.jenitennison.com/

The results of what you posted are pretty good except that I get two
sets of footnotes. I suspect that line above, hence the questions.

Do you have nested div elements?

At the end of every div I went
<xsl:for-each select=".//note">

which processes all notes however deeply nested so if you go

<div>
xxx<note>a</note>
<div>
yyy<note>b</note>
</div>
</div>

You'll get something like

xxx^1

yyy^b
1 b

1 a
1 b


as I just use the default attributes on xsl:number (which numbers notes
(just) with its siblings and processes notes on every div.

Both of these things are easy to fix but it depends quite what you want
eg one way is to add attributes to xsl:number so notes are numbered
across the whole document and move
<xsl:if test=".//note">
<hr/>
<dl>
<xsl:for-each select=".//note">
<dt><xsl:number level="any"/></dt>
<dd><xsl:apply-templates/></dd>
</xsl:for-each>
</dl>
</xsl:if>

to the end of the template that matches your book rather than having it
on every div.

David
 
J

Jeremy Porter

OK, if the TEI style sheets do not require some tex system then I am
mistaken. But I am still unable to get them to work. The html sheets
work fine. Whenever I try to use a pdf processor I get errors:

FOP:

[Fatal Error] tei-struct.xsl:1172:83: The prefix "fotex" for attribute
"fotex:column-align" is not bound.
[ERROR[ javax.xml.transform.TransformerConfigurationException: ... etc.

AltSoft:

Gives me the error $ReadColSpecFile$ variable not defined.

I wonder if there is something I need to configure to get this working.
That was another part of my motivation to write my own style sheets.

Thanks,

Jeremy
David said:
<xsl:apply-templates select="node()[not(self::head)]"/>

does.

node() is that some form of boolean function?

Not really it's a node test (along with with text() comment() and
processing-instruction()) it selects any node (* in that position
would just match element nodes. In particular if you do
<xsl:apply-templates select="node()"/>
or equivalently
<xsl:apply-templates/>
templates get applied to child text as well as child element nodes.

Obviously text nodes are never head elements so the
node()[not(self::head)]
is the same as
text()|*[not(self::head)]
(well actually it's the same as

comment()|processing-instruction()|text()|*[not(self::head)]

I was not able to find
it in the XSLT functions reference or the XPath functions. Is this
selecting all elements except "node()[not(self::head)]"?

It's in xpath.

As for writing my own XSL/XSL:FO for TEI, the style sheets that are
available for HTML are decent, I just wanted to learn XSL/XSL:FO. What
I really want is XSL:FO, but I thought XSL would be a good starting
point.

Yes that's a good idea and you'll learn more rolling your own, although
in the end you may find that to handle complicated tei books customising
sebastian's efforts might be quicker if you just want to get the job
done rather than rolling your own. For TEI (and the conceptually
similar docbook stylesheets) a lot of years fine tuning edge cases have
gone in to the stylesheets, so for any given document it's often simpler
to write your own focussed stylesheet, but to produce something that
can handle a large range of documents within the specific dtd, using a
"standard" stylesheet has advantages.


The TEI XSL:FO style sheets use PassiveTeX.

Not really, The fO files they generate can be used by any FO renderer
(FOP, renderx, ....). Passivetex was generated at the same time by the
same person (except for the low level xml parsing part which he
tricked someone else in to writing) but the stylesheets produce standard
FO (in general, they may use a few extension elements for specific jobs,
I haven't looked recently)

Logically it
seems you have to have some software installed (jadeTeX?) to process
them appropriately.

You need tex, jadetex is something else, similar to passivetex but
working with dsssl rather than xsl dsssl being the older style language
for sgml rather than xml documents (Sebastian and I have been in this
game too long:) If you are not already a tex user (why not:) to be
honest I wouldn't start with passivetex I'd start with fop if you are
looking for a free FO engine as that is by far the most commonly used
free one so you'll get more "community" support using that.

So far this seems to be a component driven process. I mean I can write
a snippet of XSL for div elements and then use it in other places
which is nice. Are there any good references on design strategies for
this kind of thing? Not just what the XSL elements are, but how to put
them together and how to do things efficiently?


xsl-list has a good faq site, jeni's site is also good

http://www.dpawson.co.uk/xsl/xslfaq.html
http://www.jenitennison.com/

The results of what you posted are pretty good except that I get two
sets of footnotes. I suspect that line above, hence the questions.

Do you have nested div elements?

At the end of every div I went
<xsl:for-each select=".//note">

which processes all notes however deeply nested so if you go

<div>
xxx<note>a</note>
<div>
yyy<note>b</note>
</div>
</div>

You'll get something like

xxx^1

yyy^b
1 b

1 a
1 b


as I just use the default attributes on xsl:number (which numbers notes
(just) with its siblings and processes notes on every div.

Both of these things are easy to fix but it depends quite what you want
eg one way is to add attributes to xsl:number so notes are numbered
across the whole document and move
<xsl:if test=".//note">
<hr/>
<dl>
<xsl:for-each select=".//note">
<dt><xsl:number level="any"/></dt>
<dd><xsl:apply-templates/></dd>
</xsl:for-each>
</dl>
</xsl:if>

to the end of the template that matches your book rather than having it
on every div.

David
 
D

David Carlisle

http://www.tei-c.org/Stylesheets/teixsl.xml.ID=body.1_div.6
It's true that the documentation does say
These style sheets were developed for use with PassiveTeX
but I wouldn't expect that to be too much of a problem passivetex is
pretty much written to process standard fo files. Like other FO systems
it does have some extensions in it's own namespace (the fotex prefix).


You appear to be falling foul of
<fo:table-column column-number="1" fotex:column-align="r"
column-width="" />
(from tei-special.xsl) or a similar construct elsewhare.

I was going to say that FO engines should ignore attributes in
namespaces that they don't recognise, but your posting indicates that
they don't and I just searched the xsl spec and didn't see any anything
to justify that belief...

these fotex attributes give the tex engine some extra hints on layout,
but just deleting them from your copy of the stylesheet should work in
most cases as far as I can see looking just now (I hadn't actually
looked recently otherwise I'd have mentioned this before, sorry)


David
 
J

Jeremy Porter

David said:
http://www.tei-c.org/Stylesheets/teixsl.xml.ID=body.1_div.6
It's true that the documentation does say
These style sheets were developed for use with PassiveTeX
but I wouldn't expect that to be too much of a problem passivetex is
pretty much written to process standard fo files. Like other FO systems
it does have some extensions in it's own namespace (the fotex prefix).


You appear to be falling foul of
<fo:table-column column-number="1" fotex:column-align="r"
column-width="" />
(from tei-special.xsl) or a similar construct elsewhare.

I was going to say that FO engines should ignore attributes in
namespaces that they don't recognise, but your posting indicates that
they don't and I just searched the xsl spec and didn't see any anything
to justify that belief...

these fotex attributes give the tex engine some extra hints on layout,
but just deleting them from your copy of the stylesheet should work in
most cases as far as I can see looking just now (I hadn't actually
looked recently otherwise I'd have mentioned this before, sorry)


David

No, need to apologize. Thank you for your help! I've got basic TEI
working for converting xml to pdf using altsoft's xml2pdf. FOP lacks
some features that I require currently, but maybe in the future it will
do what I need!

I have a number of questions regarding the TEI style sheets:

1) How can I get footnotes with multiple <p> elements working? In my
output I get:

1.
Footnote text in <p>.
more text in another <p>

Instead of:

1. Footnote text.
more text in another <p>.

2) How can I adjust the TOC hyperlinks to extend to the text entry as
well as the numeric entry?

I have currently:

Chapter 1...1
but only the page number 1 is active as a link.

3) How can I manage chapter numbers in TEI? I looked around in the
documentation and didn't see anything specific on chapter numbers aside
from the n attribute. If I use the n attribute that works great for
chapters with numbers, but what about chapters without numbers? If I
leave n blank in the chapter heading I get ". Chapter Heading" which
doesn't look quite right! I see several references to things I think I
may want to customize in tecommon.xsl. I'm not sure which ones to start
with!

4) How can I prevent page numbers from appearing in the header and
footer of the same page?

Perhaps there is some other documentation that I'm not aware of with
XSL TEI that will answer these kind of questions? It's really some good
stuff--I just don't know how to use it all!

Thanks,

Jeremy
 

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

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top