Formatting embedded tags

Discussion in 'XML' started by nutsmuggler, Dec 1, 2005.

  1. nutsmuggler

    nutsmuggler Guest

    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
    nutsmuggler, Dec 1, 2005
    #1
    1. Advertising

  2. > 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

    --
    Lars Kellogg-Stedman <>
    This email address will expire on 2005-11-23.
    Lars Kellogg-Stedman, Dec 1, 2005
    #2
    1. Advertising

  3. nutsmuggler

    nutsmuggler Guest

    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
    nutsmuggler, Dec 1, 2005
    #3
  4. nutsmuggler

    Peter Flynn Guest

    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
    Peter Flynn, Dec 1, 2005
    #4
  5. nutsmuggler

    nutsmuggler Guest

    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
    nutsmuggler, Dec 2, 2005
    #5
  6. nutsmuggler

    Peter Flynn Guest

    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/
    Peter Flynn, Dec 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. slberry
    Replies:
    0
    Views:
    403
    slberry
    May 15, 2004
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,872
    Colin Paul Gloster
    Apr 10, 2007
  3. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    394
    Thomas Dodds
    Jul 26, 2004
  4. Trans
    Replies:
    11
    Views:
    295
    micathom
    Sep 5, 2007
  5. Num GG
    Replies:
    2
    Views:
    349
    Num GG
    Nov 17, 2008
Loading...

Share This Page