473,473 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Create 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 1375
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
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...
1
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...
6
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...
4
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 =...
4
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...
3
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...
9
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...
4
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>...
2
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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...

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.