474,048 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT: processing embedded (X)HTML

je
Slightly newbie question: I have some XML to be transformed which
contains (inter
alia) tags containing text:
<tag>Foo</tag>
which sould appear unchanged in the transformed output. Using xopy-of
would seem
to be the thing to use. However, the enclosed text sometimes needs to
contain
HTML:
<tag>Click <a href="foo.html" >here</a></tag>
At the momemt I work around this by wrapping the contents in
<html>...</html>,
and using templates like this:
<xsl:template match='tag'>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match='html'>
<xsl:copy-of select="*"/>
</xsl:template>
This means I always have to generate <tag><html> ... </html></tag>,
which strikes
me as seriously ugly. Can anyone tell me a better way to deal with
this?

TIA...

Sep 14 '05 #1
2 1402
je@brighton.ac. uk wrote:
Slightly newbie question: I have some XML to be transformed which
contains (inter
alia) tags containing text:
<tag>Foo</tag>
which sould appear unchanged in the transformed output. Using xopy-of
would seem
to be the thing to use. However, the enclosed text sometimes needs to
contain
HTML:
<tag>Click <a href="foo.html" >here</a></tag>
But copy-of will preserve everything inside the enclosing element.
At the momemt I work around this by wrapping the contents in
<html>...</html>,
and using templates like this:
<xsl:template match='tag'>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match='html'>
<xsl:copy-of select="*"/>
</xsl:template>
This means I always have to generate <tag><html> ... </html></tag>,
which strikes
me as seriously ugly. Can anyone tell me a better way to deal with
this?


Don't add the extra <html>...</html>, just use copy-of:

<xsl:template match="tag">
<xsl:copy-of select="."/>
</xsl:template>

///Peter

Sep 14 '05 #2
On 14 Sep 2005 13:30:11 -0700, "je@brighton.ac .uk" <je@brighton.ac .uk>
wrote:
Slightly newbie question: I have some XML to be transformed which
contains (inter
alia) tags containing text:
<tag>Foo</tag>
which sould appear unchanged in the transformed output.


Change the design. That sort of input is a bad solution, especially if
it's an external feed.

Go read up on RSS and its many approaches to this problem. Google for
"Dive into mark" and "myth of rss compatibility" for a good article on
this topic. Also read the Atom spec.

Generally entity-encoding is the better way to go.
Sep 14 '05 #3

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

Similar topics

5
19388
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object in memory - I don't want to create XML file containing data and then load it and transform with XSLT, but I want to do this at once - without writing to a temporary file. Actually I've seen alot articles about parsing XML, but nothing about...
1
5477
by: Sven Steinacker | last post by:
Hi, XSLT files generated by Microsoft InfoPath applied to an applicable XML file produces quite decent HTML presentations. At least with Mozilla and, of course, IE 6.0 the results look the same as the original form in InfoPath. However, pictures which were included in an InfoPath form's RTF field before, are encoded in XHTML and embedded in the XML file as follows: <img style="WIDTH: 541px; HEIGHT: 330px" tabIndex="-1" height="330"...
6
2956
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
4
5263
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
4
2187
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an XSLT to produce HTML code. The problem I have is that no matter what translation it runs through, it ALWAYS includes data that I don't match in the XSLT!! All I want to do is extract specific fields from the XML. Here's the XML source....
3
2022
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as processor input. The basic class hierarchy is:
9
2203
by: starlight | last post by:
Hallo, there were some posts about this, but nothing I could find useful. I have a large XML file (80MB) and need certain information out of it. I though I could use XSLT with an fairy simple transformation: .... <xsl:for-each select="/values/STRING/item"> <tr class="own"> <td><xsl:value-of select="A"/></td> <td><xsl:value-of select="B"/></td>
4
11989
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
2
3243
by: killy971 | last post by:
I have been testing different libraries to process XSL transformations on large XML files. The fact is that I read a document from Intel, stating their library (XSLT accelerator) was more twice faster than Apache Xalan, and was designed to perform well on large XML files. - http://isdlibrary.intel-dispatch.com/isd/10/wp_XSLT.PDF - http://www.intel.com/cd/software/products/asmo-na/eng/366637.htm Please note that their benchmark was only...
0
10557
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
10358
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
12049
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7882
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
6670
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
6865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5430
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

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.