473,394 Members | 2,168 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,394 software developers and data experts.

xalan xsl

Hi,
I have the following problem:
I want convert XML in the form:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>

<row><value>1-String</value><value>2-String</value><value>3-String</value></row>

<row><value>r1-String</value><value>r2-String</value><value>r3-String</value></row>
</dataset>

to HTML for example

I wrote a small stylesheet:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<table border="1">
<xsl:apply-templates select="dataset/row"/>
</table>
</xsl:template>

<xsl:template match="dataset/row">
<tr>
<xsl:apply-templates select="value"/>
</tr>
</xsl:template>

<xsl:template match="value">
<td>
<xsl:value-of select='.'/>
</td>
</xsl:template>
</xsl:stylesheet>

The stylesheet works fine with my xsltproc.
The out put is:

<table border="1">
<tr>
<td>1-String</td>
<td>2-String</td>
<td>3-String</td>
</tr>
<tr>
<td>r1-String</td>
<td>r2-String</td>
<td>r3-String</td>
</tr>
</table>

However when I try to run this stylesheet with the Xalan library from
within a java application,
with a TransformerHandler I get from SAXTransformerFactory, the result
is only:

<table border="1"></table>

Can someone give me a hint ?

Thomas

Apr 11 '06 #1
6 1489
th***************@osp-dd.de wrote:
Hi,
I have the following problem: [snip] However when I try to run this stylesheet with the Xalan library from
within a java application,
with a TransformerHandler I get from SAXTransformerFactory, the result
is only:

<table border="1"></table>

Can someone give me a hint ?


Your XML and XSLT are correct. Therefore the software is broken
and should be replaced with something that works.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Apr 11 '06 #2
I'd have to see the Java application. Make sure the source document is
being built as namespace-aware, with the namespace declaration attributes.

You may want to try your stylesheet with some of the simple drivers that
come with Xalan. If it works with those, compare them with your own code
and fix the latter.
Apr 11 '06 #3
Joseph Kesselman schrieb:
I'd have to see the Java application. Make sure the source document is
being built as namespace-aware, with the namespace declaration attributes.

You may want to try your stylesheet with some of the simple drivers that
come with Xalan. If it works with those, compare them with your own code
and fix the latter.


The problem I have is that I programmed against the javax.xml.
interfaces.
In the code I say nowhere "take xalan".

The code looks like:

TransformerFactory transFact =
TransformerFactory.newInstance();

SAXTransformerFactory saxTransFact = (SAXTransformerFactory)
transFact;
TransformerHandler transHand = null;

transHand = saxTransFact.newTransformerHandler(new
StreamSource(xsltFileName));
transHand.setResult(new StreamResult(System.out));

javax.xml.transform.Result result =
new javax.xml.transform.stream.StreamResult(System.out );

StringArrayXMLReader saReader;
try {
saReader = new StringArrayXMLReader(transHand);
saReader.init();
saReader.parse(arr);
saReader.parse(arr2);
saReader.close();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

arr and arr2 are String-arrays.

I can run the code without xalan in my CLASSPATH and I get the wrong
result.
Apparently the SDK itself provides some xslt functionality.
The question is now how can I specify that xalan is used ?

When I run the example above without xsl-Stylesheet,

transHand = saxTransFact.newTransformerHandler();

I get my pure XML-output:

<?xml version="1.0" encoding="UTF-8"?>
<dataset><row><value>1-String</value><value>2-String</value><value>3-String</value></row><row><value>R1-String</value><value>R2-String</value><value>R3-String</value></row></dataset>
which is correct.

Apr 12 '06 #4

Joseph Kesselman schrieb:
I'd have to see the Java application. Make sure the source document is
being built as namespace-aware, with the namespace declaration attributes.

You may want to try your stylesheet with some of the simple drivers that
come with Xalan. If it works with those, compare them with your own code
and fix the latter.


I tried the example from
http://www.topxml.com/java/articles/xslt/default.asp
with the 3 files: AbstractXMLReader.java CSVXMLReader.java
SimpleCSVProcessor.java

The example Example 5-9: csvToHTMLTable.xslt does not work when I
specify the stylesheet. It creates a output:

<table border="1"></table>

instead of a full table output.

Still any hint ?

Apr 13 '06 #5
It would help if the book's code wasn't broken. He's passing the
localname as "". That doesn't match SAX's design.

Start by changing all the SAX event calls to fix this -- eg, change
ch.startElement("","","line",EMPTY_ATTR);
to
ch.startElement("","line","line",EMPTY_ATTR);
and so on.

Moral: Don't assume that code is right just because it's been published.
That hopefully means it was tested on one implementation... but that
implementation may have been wrong, and I *have* seen code published
that wasn't tested at all.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 17 '06 #6

Joe Kesselman schrieb:
It would help if the book's code wasn't broken. He's passing the
localname as "". That doesn't match SAX's design.

Start by changing all the SAX event calls to fix this -- eg, change
ch.startElement("","","line",EMPTY_ATTR);
to
ch.startElement("","line","line",EMPTY_ATTR);
and so on.

Moral: Don't assume that code is right just because it's been published.
That hopefully means it was tested on one implementation... but that
implementation may have been wrong, and I *have* seen code published
that wasn't tested at all.

Thanks a lot for your message ! It solved the problem and now I have
to read more about
the SAX design. And yes it is awkward to publish broken code as ad for
a book.

Apr 18 '06 #7

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

Similar topics

5
by: al dav | last post by:
Hi all ok i am not a java programmer I am a sys-admin, my users want xalan and have already got j2sdk_1.4.2 so i have downloaded it and set the CLASS_PATH export...
0
by: Guillaume Jeudy | last post by:
Hi, I'm trying to serialize a DOM constructed from the following URL which is subject to change very frequently: ...
1
by: Fisch von Gestern | last post by:
I have tried to run the extension function/element examples provided with the Xalan-J download. I believe that my classpath is correct, and that my versions are up-to-date. However, I can't get...
7
by: Ganesh Gella | last post by:
Hi All, I am planning to use Xalan to transform XML data by applying xls stylesheets. Here tricky part is, Xalan provides several C++ APIs, which are very much useful if our requirement is...
2
by: Dr. Roger Wießner | last post by:
Hello! I am a newbie to XSLT and need a freeware/GNU Tool to get experience with this new topic. Which one is a good XSLT? Xalan or Saxon, or which one else? Thank you a lot!
5
by: John | last post by:
I'm trying to generate HTML using a SAX TransformHandler. The problem I'm having is related to the xalan transformer using the shorthand notation when it writes out an empty textarea tag. My...
7
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
0
by: terry.jeske | last post by:
Hello, I am trying to upgrade an application that was previously running on Xalan 1.4.2, to 2.7.0. I have worked out the build issues and now the application compiles with the new xalan and...
3
by: Avalon1178 | last post by:
Hi, I recently downloaded the xalan-c source code in http://mirrors.ccs.neu.edu/Apache/dist/xml/xalan-c I followed the instructions from the apache site on how to build it (I already have...
2
by: henribastien | last post by:
I'm trying to return an array from a xalan extension but so far I have made no progress. What I would like to return is something like that <entry id="red">201</entry> <entry...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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...
0
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...

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.