Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Formatting embedded tags

Reply
Thread Tools

Formatting embedded tags

 
 
nutsmuggler
Guest
Posts: n/a
 
      12-01-2005
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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

 
Reply With Quote
 
 
 
 
Lars Kellogg-Stedman
Guest
Posts: n/a
 
      12-01-2005
> 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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput 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

--
Lars Kellogg-Stedman <(E-Mail Removed)>
This email address will expire on 2005-11-23.

 
Reply With Quote
 
 
 
 
nutsmuggler
Guest
Posts: n/a
 
      12-01-2005
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

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      12-01-2005
nutsmuggler wrote:

> 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
 
Reply With Quote
 
nutsmuggler
Guest
Posts: n/a
 
      12-02-2005
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

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      12-03-2005
nutsmuggler wrote:

> 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
--
XML FAQ: http://xml.silmaril.ie/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded vs. Non-embedded Tests Trans Ruby 11 09-05-2007 11:22 AM
Embedded languages based on early Ada (from "Re: Preferred OS, processor family for running embedded Ada?") Colin Paul Gloster VHDL 48 04-10-2007 10:31 AM
How to display images embedded in e-mail as embedded, not attachments Jim Firefox 4 12-11-2004 05:36 AM
Databind an embedded control in an embedded datagrid Thomas Dodds ASP .Net Datagrid Control 0 07-26-2004 08:20 PM
Need Help Converting formatting tags embedded in entities to XSL:FO instructions slberry XML 0 05-15-2004 01:48 AM



Advertisments