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:stylesheet 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="normalize-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%">Column 1</td>
<td width="25%">Column 2</td>
<td width="20%">Column 3</td>
<td width="20%">Column 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:)
3 9490
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="' '" />
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:stylesheet 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="normalize-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%">Column 1</td>
<td width="25%">Column 2</td>
<td width="20%">Column 3</td>
<td width="20%">Column 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:)
Instead of using <xsl:value-of select="."/>
I suggest using <xsl:apply-templates/>
Then have 2 templates like so: - <xsl:template match="tr">
-
<xsl:apply-templates/>
-
<xsl:text>
-
</xsl:text><!-- add a newline -->
-
</xsl:template>
-
-
<xsl:template match="td">
-
<xsl:text> </xsl:text>
-
<xsl:apply-templates/>
-
<xsl:text> </xsl:text>
-
</xsl:template>
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: mark4asp |
last post by:
I have an element, report which contains tags which have been
transformed. E.g. <pis <p>
<myXml>
<report>This text has html tags in it.<p> which but <has been
changed to <></report>...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
| |