Formatting embedded tags

N

nutsmuggler

Hi.
I am using xml to store my annotations.
here is my document (a part of it):

<?xml version="1.0" encoding="UTF-8"?>
<text title="Finnegan's wake">
<book number="1">
<chapter number="5">
<note p="107"> script: <q>proteiform graph, polyhedron of
scripture, etc</q>
</note>
<note p="107"> authorship </note>
<note p="108"> abc and authorship; relationship between
speech and prose </note>
<note p="110">vernacular</note>
<note p="110">ahahn: is it a zen-like revelation?</note>
<note p="111">funferral, bakhtnian carnival</note>

etc..


I use an xsl stylesheet to produce html output.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html" version="1.0" encoding="UTF-8"
indent="no"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"/>
<title>Notes</title>
</head>
<body>
<h1>
<xsl:value-of select="text/@title"/>
</h1>
<xsl:for-each select="text/book">
<h2>Book <xsl:value-of select="@number"/></h2>
<xsl:for-each select="chapter">
<h3>Chapter <xsl:value-of select="@number"/>
</h3>
<xsl:for-each select="note"> - p. <xsl:value-of
select="@p"/>: <xsl:value-of
select="."/>
<br/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I would like to manipulate the q tags (q stands for quote), getting an
output like (I'll use my first note as an example):

p 107: script: "proteiform graph, polyhedron of scripture, etc"

Yet I cannot manipulate the embedded q tag. The problem is that the tag
must be embedded, because of its own nature...
Any suggestion?
Thans in advance,
Davide
 
L

Lars Kellogg-Stedman

I would like to manipulate the q tags (q stands for quote), getting an
output like (I'll use my first note as an example):

This is actually easy -- easier, I think, if you make more use of
<xsl:apply-templates/> rather than the <xsl:foreach/> loops you're
currently using.

Have a look at the following stylesheet. I think it will do what you
want.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:eek:utput method="html" version="1.0" encoding="UTF-8"
indent="no" />

<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<title>Notes</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="text">
<h1>
<xsl:value-of select="@title" />
</h1>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="text/book">
<h2>Book
<xsl:value-of select="@number" /></h2>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="text/book/chapter">
<h3>Chapter
<xsl:value-of select="@number" /></h3>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="note">
- p. <xsl:value-of select="@p" />: <xsl:apply-templates /><br/>
</xsl:template>

<!-- This template matches <q> elements. I've actually just
passed <q> on to the output, since browsers will recognize this as
a quote mark and it can be styled with CSS. -->
<xsl:template match="q">
<q><xsl:apply-templates/></q>
</xsl:template>
</xsl:stylesheet>

-- Lars
 
N

nutsmuggler

What can I say?
Thanks a million, you solved my issue.
Also, I finally understand the using of "xsl:apply-templates", which
was a mistery to me.
Thanks again,
Davide
 
P

Peter Flynn

nutsmuggler said:
What can I say?
Thanks a million, you solved my issue.
Also, I finally understand the using of "xsl:apply-templates", which
was a mistery to me.

It would be hugely useful to those of us who write documentation
to try and understand where the problem lay so that we can write
something better. If you have a few minutes, I'd be grateful if
you could set down the train of thought which led you to use the
for-each approach.

///Peter
 
N

nutsmuggler

Well, honestly I am not really experienced in xml and xsl..
I use xml for very practical purpouses; I am literary researcher, and I
was looking for the right way to encode my annotations.
I guess I used the "for-each" approach because it was the first I could
find on the online manuals I consulted (www.html.it).
I knew the existence of the apply-templates strategy, but I could never
understand fully how it works; as a very-practically-oriented xml user
I just discarded the strategy I could not understand. I have always
been using just the value-of command..
Now, thanks to Lars's example I got some hold on the recursive
principle behind the xsl:apply-templates command.
That' more or less how things went
Now I guess the "apply-templates" is more reccomended as an approach...
Cheers,
Davide
 
P

Peter Flynn

nutsmuggler said:
Well, honestly I am not really experienced in xml and xsl..
I use xml for very practical purpouses; I am literary researcher, and
I was looking for the right way to encode my annotations.

Have you looked at the Text Encoding Initiative (www.tei-c.org). It
provides a DTD/Schema for literary encoding which has become the de
facto standard in the Humanities. It's very large, but its modular
construction means you can generate a subset suitable for your needs.
The advantages are that there is a huge existing user base, some good
software, lots of support, and pre-written XSLT for formatting which
you can modify to suit. Plus you would be creating XML that conforms
to the standard that the rest of the field is using.
I guess I used the "for-each" approach because it was the first I
could find on the online manuals I consulted (www.html.it).
I knew the existence of the apply-templates strategy, but I could
never understand fully how it works; as a very-practically-oriented
xml user I just discarded the strategy I could not understand. I have
always been using just the value-of command..
Now, thanks to Lars's example I got some hold on the recursive
principle behind the xsl:apply-templates command.
That' more or less how things went

That's very useful, thanks. Clearly we need to improve the visibility
of XSLT documentation.

///Peter
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top