Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating html using xml and xslt

Status
Not open for further replies.

eliphas

Technical User
Apr 6, 2007
5
GB
Hi all,
I'm currently designing a website for a poet, and as I've been looking for an opportunity to try out xml I've decided to have a go at storing all the poem files in xml format.

The general structure goes like this:
<poem>
<verse>
<line>This would be the first line of the poem</line>
<line>This would be the second line of the poem</line>
...
</verse>

<verse>
...
</verse>
</poem>

I know this is a simple case, but my main reason for doing the site this way is as a learning exercise.

I have written an xslt file to display the poem, each verse is displayed as a separate <p> tag, and a <br/> tag is inserted at the end of each line.

So far so good!

My problems begin when I try to expand on what I already have! Ideally I would like to include both <strong> and <em> tags into the poem files for a little extra control over the formatting, but I don't know how to make the xslt change the <strong> tags in my xml file into normal html <strong> tags whilst keeping the rest of the <line> element intact.

I've searched through all my books and forums and can't find anything that addresses this particular problem. If anybody could point me in the right direction I would be grateful.

Many thanks.
 
I'd like to say thanks to anyone who may be reading this and thinking about helping me, but I think I've finally cracked it!

I used this:

<xsl:template match="line">
<xsl:text disable-output-escaping="no"/>
<br/>
</xsl:template>

It seems to work, but I'd still welcome any comments from people with advice about whether this is the best answer or if you know any other ways.

Many thanks.
 
Sorry it seems I lied, that doesn't work at all. Back to the drawing board!!!
 
[0]
[tt]<!-- ancestors etc etc -->
<!-- lines etc etc -->
<line>Porque parte tudo um dia</line>
<line>O que nos lábios ardia</line>
<line>Até não sermos ninguém</line>
<line><strong>Tudo é água</strong>que corre</line>
<line>De cada vez que nos morre</line>
<line>Nasce um pouco mais além</line>
<!-- line etc etc -->
<!-- closing ancestors etc etc -->
[/tt]
[1] Important to be specific (with parent line specified) for mixed content model.
[tt]
<xsl:template match="line">
<xsl:apply-templates select="text()|node()" />
<br />
</xsl:template>
<xsl:template match="[blue]line[/blue]/text()">
<xsl:value-of select="normalize-space()" />
</xsl:template>
<xsl:template match="[blue]line[/blue]/strong">
<xsl:text>&#x20;</xsl:text>
<span style="font-weight:bold">
<xsl:value-of select="normalize-space()" />
</span>
<xsl:text>&#x20;</xsl:text>
</xsl:template>
[/tt]
 
Thanks tsuji, you just about saved my sanity!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top