473,507 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting embedded tags

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:output 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

Dec 1 '05 #1
5 1382
> 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:output 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 <82*************@jetable.net>
This email address will expire on 2005-11-23.

Dec 1 '05 #2
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

Dec 1 '05 #3
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
Dec 1 '05 #4
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

Dec 2 '05 #5
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/

Dec 3 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3538
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred...
4
1830
by: Rob Meade | last post by:
Hi all, Ok - this leads on from speaking to a couple here and in the SQL server group... I've an application which allows the user to type in their text into a form, they add 'happy' tags...
0
1274
by: slberry | last post by:
I have a client sending me XML where there are formatting tags embedded in XML entities.... i.e. <p content="This is &lt;B&gt;bold, and &lt;I&gt;bold-italic&lt;/I&gt;&lt;/B&gt;"/> I need to convert the entity to the...
4
3147
by: Luke Dalessandro | last post by:
I have some XML data that has mixed content XML tags that embed XHTML tags, for instance: <note>Somebody wrote this note in XHTML and wanto to <a href="link.html" target="_new">link</a> to a...
163
14481
by: Shiperton Henethe | last post by:
Hi Know any good utilities to help me strip out the tags that Microsoft Excel 2002 leaved behind when you try and export an HTML format file? This is driving me NUTS. And really makes me...
6
8970
by: Kevin G. | last post by:
I'm not sure if this is possible, but if a page uses a CSS style sheet and you would still like to use good old <font> tags... is there a tag to tell the browser to ignore the CSS formatting just...
2
1925
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
1584
by: Arthur Dent | last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just getting my feet with now with v.2. Ive noticed something strange in the way my HTML tables get rendered with 2. I use...
2
1459
by: rickholt | last post by:
Many years ago at IBM we had a text formatting language (DCF) which let you specify all sorts of microcommands to a page formatter. Not particularly exciting, but it was also a primitive...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.