473,624 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML Via XSLT to Plain Text output

2 New Member
Hi All.
I'm trying to transform a html document into plain text via xslt.
Simple you say! (i hope)
I have got it working, by using the magnificent <xsl:value-of select="."/>.
This returns the whole document, and <xsl:output method="text"/> ensures that the output I get is plain text.
problem:
The html I am transforming has a table, with headings and data. Whilst the output contains all the data form the table, it does not preserve any formatting, and concatenates all the data within the table.
Can you suggest how i could extract the data from the table, and present in plain text? The only formatting I require, is that the spacing between the columns is somewhat preserved.
I am, as im sure you can tell, an xslt noob still, even with many years of application development under my belt!.
Thanks for all your help!

Xslt:

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="."/>
<xsl:value-of select="normali ze-space(.)"/>
</xsl:template>
</xsl:stylesheet>

Html:

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD></HEAD>
<BODY>
<p>Dear person,</p>
<p>The following are columns are required to preserve the formatting.</p>
<table cellpadding="0" cellspacing="0" width="50%">
<tr>
<td width="20%">Col umn 1</td>
<td width="25%">Col umn 2</td>
<td width="20%">Col umn 3</td>
<td width="20%">Col umn 4</td>
</tr>
<tr>
<td><font size="4">01/06/2008</font></td>
<td><font size="4">34.2</font></td>
<td><font size="4">A Name</font></td>
<td><font size="4">42.00</font></td>
</tr>
</table>
</BODY>
</HTML>


result:
somethign like...

Dear person, The following are columns are required to preserve the formatting. Column 1Column 2Column 3Column 401/06/200834.2A Name42.00
;
Any suggestions would be welcome:)
Oct 3 '07 #1
3 9555
Gaiason
5 New Member
Hi I'm also noob, but I manage to find this code for space

You can try adding this within the template:
<xsl:value-of select="'&#x20; '" />
or
<xsl:text> </xsl:text>

Hope it helps.

Cheers,
Gaiason

Hi All.
I'm trying to transform a html document into plain text via xslt.
Simple you say! (i hope)
I have got it working, by using the magnificent <xsl:value-of select="."/>.
This returns the whole document, and <xsl:output method="text"/> ensures that the output I get is plain text.
problem:
The html I am transforming has a table, with headings and data. Whilst the output contains all the data form the table, it does not preserve any formatting, and concatenates all the data within the table.
Can you suggest how i could extract the data from the table, and present in plain text? The only formatting I require, is that the spacing between the columns is somewhat preserved.
I am, as im sure you can tell, an xslt noob still, even with many years of application development under my belt!.
Thanks for all your help!

Xslt:

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="."/>
<xsl:value-of select="normali ze-space(.)"/>
</xsl:template>
</xsl:stylesheet>

Html:

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD></HEAD>
<BODY>
<p>Dear person,</p>
<p>The following are columns are required to preserve the formatting.</p>
<table cellpadding="0" cellspacing="0" width="50%">
<tr>
<td width="20%">Col umn 1</td>
<td width="25%">Col umn 2</td>
<td width="20%">Col umn 3</td>
<td width="20%">Col umn 4</td>
</tr>
<tr>
<td><font size="4">01/06/2008</font></td>
<td><font size="4">34.2</font></td>
<td><font size="4">A Name</font></td>
<td><font size="4">42.00</font></td>
</tr>
</table>
</BODY>
</HTML>


result:
somethign like...

Dear person, The following are columns are required to preserve the formatting. Column 1Column 2Column 3Column 401/06/200834.2A Name42.00
;
Any suggestions would be welcome:)
Oct 3 '07 #2
jkmyoung
2,057 Recognized Expert Top Contributor
Instead of using <xsl:value-of select="."/>
I suggest using <xsl:apply-templates/>
Then have 2 templates like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="tr">
  2.   <xsl:apply-templates/>
  3.     <xsl:text>
  4. </xsl:text><!-- add a newline -->
  5. </xsl:template>
  6.  
  7. <xsl:template match="td">
  8.   <xsl:text> </xsl:text>
  9.     <xsl:apply-templates/>
  10.   <xsl:text> </xsl:text>
  11. </xsl:template>
Oct 3 '07 #3
realmerl
2 New Member
Thanks for your replies, I will give it a go.
Might just use regex to strip out all html tags, seems to work ok for our needs.
Oct 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2741
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
3
7909
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root element during transformation, it return s "java.lang.IllegalStateException: Root element not set" exception. If I add any element for the enclosed root, it works. Note: I am using XMLOutputter object of JDOM API, packages javax.xml.transform and...
2
3397
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
1
2527
by: shea | last post by:
I have an XML data type which I would like to display in my HTML. The data type looks somthing like this: <package name="helloworld"> <description> This is a program which prints hello world to a terminal. </description> <file uri="hellos.zip" name="source code" size="100bytes"/> <file uri="hellob.zip" name="binaries" size="300bytes"/> <package>
3
2128
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty string. I expected the xml to be transformed into a plain text document. Everything works fine when i transform using XmlPad. Here's the code (which does generate the Xml properly): Sample XML:
5
1931
by: eva.mukhija | last post by:
Hi I need to insert some html content generated by certain business logic into an xsl output. I have been able to insert custom Java extensions and generate the HTML to be outputted. My problem is that xsl transformation is not resulting in rendering the content as HTML. I've tried xsl:copy-of and xsl:text. I think it is probably generating a text node with the given content and writes entire html code as it is rather than rendering it....
12
11578
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I don't want to have to use some external program or script to parse the csv first if possible
6
5839
by: ronburk | last post by:
Is there any standard way to control the end-of-line convention (LF versus CR/LF) for XSLT processor output? The obvious logical point to control this would be in xsl:output. However, Kay says of its 'media-type' attribute "The specification doesn't say what use is made of this information", which sounds pretty discouraging. I wonder how many XSLT processors running on *nix actually emit CR/LF sequences when the output media-type is set...
4
11923
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?
0
8233
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
8170
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
8619
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
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
8474
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...
0
7158
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
5561
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
4078
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
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.