473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

XML to many HTML files

2
I want to transform an XML file into many HTML files using XSL and JAXP. I am able to successfully generate many HTML files. But when description element is more than one paragraph, I am not able to do this. Also any HTML formatting to the text in description is not working. ex: to show some words in bold.
Below are the code snippets I am using. I use command prompt to call the classfile and passing xml and xsl file names as arguments.
can some one throw some light on this.
Regards,

Nagesh
------------------

A sample of XML file is as below
products.xml
<products>
<category>gift products</category>
<product>
<title>this is product One </title>
<image>images/product1.gif</image>
<price-range>$30-$50</price-range>
<description>This product is useful for the below occasions. two more praragraphs </description>
</product>
<product>
<title>this is product Two </title>
<image>images/product2.gif</image>
<price-range>$70-$80</price-range>
<description>Kids like this product. paragraphs of discription</description>
</product>
</products>


my xsl file is as below
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="org.apache.xalan.xslt.extensions.Redi rect"
extension-element-prefixes="xalan">

<xsl:output method="html"/>

<xsl:template match="products">
<html>
<head><title><xsl:value-of select="category"/></title></head>
<body>
<h1><xsl:value-of select="category"/></h1>
<p>The details are <a href="product-1.html">here</a>.</p>
</body>
</html>
<xsl:apply-templates select="product"/>
</xsl:template>

<xsl:template match="product">
<xalan:write select="concat('product-',position(),'.html')">
<html>
<head><title><xsl:value-of select="title"/></title></head>
<body>
<TABLE border ="1" width ="70%">
<TR >
<TD>Title :</TD>
<td><h1><xsl:value-of select="title"/></h1></td>
</TR>

<TR>
<TD>Price range:</TD>
<TD><xsl:value-of select="price-range"/></TD>
</TR>
<TR>
<TD>Description:</TD>
<TD><xsl:value-of select="description"/></TD>
</TR>
<TR>
<TD>Photo: </TD>
<TD><img src="{image}" align="left"/> </TD>
</TR>
</TABLE>
</body>
</html>
</xalan:write>
</xsl:template>

</xsl:stylesheet>

my java file is as below
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Transform
{
public final static void main(String[] args)
throws IOException, TransformerException, TransformerConfigurationException
{
if(args.length < 2)
{

System.err.println(" incorrect parameters");
return;
}

File input = new File(args[0]),
style = new File(args[1]);
String base = args[0];
int pos = base.lastIndexOf('.');
if(pos != -1)
base = base.substring(0,pos);
TransformerFactory factory = TransformerFactory.newInstance();


Transformer transformer = factory.newTransformer(new StreamSource(style));
Source source = new StreamSource(input);
File resultFile = new File(base + '.' + transformer.getOutputProperty(OutputKeys.METHOD));
if(resultFile.getAbsoluteFile().equals(input.getAb soluteFile()))
resultFile = new File("transform-" + base + '.' + transformer.getOutputProperty(OutputKeys.METHOD));
Result result = new StreamResult(resultFile);
transformer.transform(source,result);
}
}
Aug 27 '07 #1
2 1507
jkmyoung
2,057 Expert 2GB
Did you want multiple hyperlinks if there are multiple products?
I only see one at the moment.

If you have html in your description node, I suggest using copy-of instead. eg:
<TD><xsl:copy-of select="description/node()"/></TD>
Aug 28 '07 #2
siddun
2
Did you want multiple hyperlinks if there are multiple products?
I only see one at the moment.

If you have html in your description node, I suggest using copy-of instead. eg:
<TD><xsl:copy-of select="description/node()"/></TD>
Hi Thanks,
I will test it over the weekend
Siddu
Aug 31 '07 #3

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

Similar topics

8
by: Nils | last post by:
Hello, my problem: I merged about 1.000 Tables with Create table name (variables) type=merge union=(table1,table2,...,table1000); MySQL now creates a tables, but I can't open it....
9
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to...
12
by: confused | last post by:
After expressing my interest in expanding my new knowledge of HTML and CSS into the wild realm of JavaScript, I was advised that it is wiser to avoid it, since not all browsers are use it or are...
4
by: Darius | last post by:
How to distribute a C program into many C files ? this is the first question a C programmer asks after learning C basics, Questions like --what is a header file --where should i put global...
1
by: Aaron via DotNetMonster.com | last post by:
I am testing for several file types in a directory by creating an array of masks and for each mask in the array, I execute a GetFiles. My issue is that the VB code: ...
59
by: Lennart Björk | last post by:
Hi All, I have a tiny program: <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>MyTitle</title> <meta...
2
by: Alan Searle | last post by:
I have built several simple XML/XSL reports and so far have put the declaration of the style sheet (xsl) in the header of the XML file. e.g. <?xml version="1.0" encoding="iso-8859-1"?>...
12
by: tienlx | last post by:
Hi, I'm learning C++, i wrote a small project that has these files: Log.h Log.cpp Render.h Render.cpp Tid.h
6
by: AMD | last post by:
Hello, I need to split a very big file (10 gigabytes) into several thousand smaller files according to a hash algorithm, I do this one line at a time. The problem I have is that opening a file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.