473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Very Interesting XSL Question

Hi, I'd greatly appreciate it if someone could cast light on my problem - I
can't seem to find any reference to it anywhere. Consider the following XML:

<paragraph> I am <emphasize>emphasized</emphasize> text inside a paragraph
</paragraph>

How do I go about transforming this into HTML like the following:

<P>I am <EM>emphasized</EM> text inside a paragraph</P>

The problem is that <emphasize> is a child of <paragraph>, but <paragraph>
itself contains textual data too. The best I can do is to get the emphasized
text output after the paragraph, not inside it!

One solution which I do not want to go down because of its unweildyness is:

<paragraph>
<text>I am </text>
<emphasize>emphasized</emphasize>
<text> text inside a paragraph </text>
</paragraph>

Many thanks in advance,

Fran
Jul 20 '05 #1
3 1687
I can't figure out why you think it will cause a problem. If you just want
to switch <paragraph> to <P> and <emphasize> to <EM>, you write:

<xsl:template match="paragraph">
<P><xsl:apply-templates/></P>
</xsl:template>

<xsl:template match="emphasize">
<EM><xsl:apply-templates/></EM>
</xsl:template>

the default template processing takes care of all the text nodes.
"Fran Cotton" <a@b> wrote in message
news:3f********@mk-nntp-2.news.uk.tiscali.com...
Hi, I'd greatly appreciate it if someone could cast light on my problem - I can't seem to find any reference to it anywhere. Consider the following XML:
<paragraph> I am <emphasize>emphasized</emphasize> text inside a paragraph
</paragraph>

How do I go about transforming this into HTML like the following:

<P>I am <EM>emphasized</EM> text inside a paragraph</P>

The problem is that <emphasize> is a child of <paragraph>, but <paragraph>
itself contains textual data too. The best I can do is to get the emphasized text output after the paragraph, not inside it!

One solution which I do not want to go down because of its unweildyness is:
<paragraph>
<text>I am </text>
<emphasize>emphasized</emphasize>
<text> text inside a paragraph </text>
</paragraph>

Many thanks in advance,

Fran

Jul 20 '05 #2
"Fran Cotton" <a@b> a écrit dans le message de news:3f********@mk-nntp-2.news.uk.tiscali.com...
Hi, I'd greatly appreciate it if someone could cast light on my problem - I
can't seem to find any reference to it anywhere. Consider the following XML:

<paragraph> I am <emphasize>emphasized</emphasize> text inside a paragraph
</paragraph>

How do I go about transforming this into HTML like the following:

<P>I am <EM>emphasized</EM> text inside a paragraph</P>


<xsl:template match="paragraph" >
<P><xsl:apply-templates /></P>
</xsl:template>
<xsl:template match="emphasize" >
<EM><xsl:apply-templates /></EM>
</xsl:template>
--
Patrick Peccatte
www.softexperience.com
Jul 20 '05 #3
Fran Cotton wrote:
Hi, I'd greatly appreciate it if someone could cast light on my problem - I
can't seem to find any reference to it anywhere. Consider the following XML:

<paragraph> I am <emphasize>emphasized</emphasize> text inside a paragraph
</paragraph>

How do I go about transforming this into HTML like the following:

<P>I am <EM>emphasized</EM> text inside a paragraph</P>

The problem is that <emphasize> is a child of <paragraph>, but <paragraph>
itself contains textual data too. The best I can do is to get the emphasized
text output after the paragraph, not inside it!


Two Solutions.

First one: use the generix <xsl:apply-templates/>. Like this:

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="paragraph">
<P>
<xsl:apply-templates/>
</P>
</xsl:template>

<xsl:template match="emphasize">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>

This is the simpler Way.

If you need to selectively process the content of paragraph, you may
want to use node():

<xsl:template match="paragraph">
<p>
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="name()='EM'">
<em><xsl:apply-templates/></em>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</p>
</xsl:template>

As you can see, this example is a little bit bad for the second variant.

--
Erhard Schwenk

Akkordeonjugend Baden-Württemberg - http://www.akkordeonjugend.de
K-ITX Webhosting - http://webhosting.k-itx.net

Jul 20 '05 #4

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

Similar topics

3
by: Winston Smith | last post by:
Hi, I have question about compiling multiple source files with templates using gcc. It's probably obvious but I'm new to C++. I've tried to isolate my problem and it came down to this. Lets...
6
by: Werner Partner | last post by:
I use a page created by php. It should show two pictures of a person an a short text. If there are no picture, nothing is shown, if there is no text, nothing is shown. There a about 20...
2
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server";...
6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
14
by: Peter | last post by:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char input_string; printf("Please enter conversion: "); scanf("%s", input_string);
3
by: Jesper Denmark | last post by:
Within the following construction switch (expression) { int i; i = GetArgs() //return 2 case constant-expression:
1
by: violetgorman | last post by:
Hello..! My name is Violet.! I am new to this forum and I am really excited about this Discussion and would love any kind of guidance. I hope someone can help me with this question that I have..I...
52
by: robert | last post by:
I'm very pleased to announce that Foundations of F#, the first book to be published on the F# programming, will finish its first printing run, tomorrow, Friday 25th May. It should reach any...
0
by: vytas | last post by:
Hello, I've ran into very interesting task and need some ideas how to implement it. I'm building web app, which has a page for importing data - importing involves very long calculations, which...
126
by: jacob navia | last post by:
Buffer overflows are a fact of life, and, more specifically, a fact of C. All is not lost however. In the book "Value Range Analysis of C programs" Axel Simon tries to establish a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.