473,698 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>emph asized</emphasize> text inside a paragraph
</paragraph>

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

<P>I am <EM>emphasize d</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>emph asized</emphasize>
<text> text inside a paragraph </text>
</paragraph>

Many thanks in advance,

Fran
Jul 20 '05 #1
3 1707
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="paragrap h">
<P><xsl:apply-templates/></P>
</xsl:template>

<xsl:template match="emphasiz e">
<EM><xsl:appl y-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.tisca li.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>emph asized</emphasize> text inside a paragraph
</paragraph>

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

<P>I am <EM>emphasize d</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>emph asized</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.tisca li.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>emph asized</emphasize> text inside a paragraph
</paragraph>

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

<P>I am <EM>emphasize d</EM> text inside a paragraph</P>


<xsl:template match="paragrap h" >
<P><xsl:apply-templates /></P>
</xsl:template>
<xsl:template match="emphasiz e" >
<EM><xsl:appl y-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>emph asized</emphasize> text inside a paragraph
</paragraph>

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

<P>I am <EM>emphasize d</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="paragrap h">
<P>
<xsl:apply-templates/>
</P>
</xsl:template>

<xsl:template match="emphasiz e">
<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="paragrap h">
<p>
<xsl:for-each select="node()" >
<xsl:choose>
<xsl:when test="name()='E M'">
<em><xsl:appl y-templates/></em>
</xsl:when>
<xsl:otherwis e>
<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
1509
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 say my source files are : === foo.h ===
6
1943
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 persons, some of them ghave two pictures, some of them one or none. Some of them have text. Every person has an indexword as for instance "meyer", there can be a
2
4933
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"; c.Open(); SqlCommand command = c.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "select Customers.customerid, customers.companyname, " +
6
2650
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 splitting up the XML into several XML documents (perhaps 50,000 per document) to be more efficient but this will make things a lot more complex because the searching needs to go accross all 500,000 records. Can anyone point me to some best practices...
14
1546
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
1548
by: Jesper Denmark | last post by:
Within the following construction switch (expression) { int i; i = GetArgs() //return 2 case constant-expression:
1
1620
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 found this article to be very interesting. The good news for me...Who is a moderator of this topic..?? If anyone has any info. on this subject ( recipies are also welcome) I would greatly appreciate a reply at
52
2521
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 pre-order customers between 5 to 10 days later, meaning if ordered it on Amazon or Borders (or any other online store), it should be with you before the end of May. A few weeks after that it should start appearing in books stores, at least bookstores...
0
970
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 can't be optimized. I'd like to start some kind of process right after file upload, and redirect user to another page, which shows calculation progress (page will refresh itself using javascript). Question is - what technology should I use? I thought...
126
4375
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 theoretical framework for analyzing C programs. In contrast to other books where the actual technical difficulties are "abstracted away", this books tries to analyze real C programs taking into account pointers, stack frames, etc.
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 we have to send another system
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.