473,396 Members | 1,785 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,396 software developers and data experts.

Why is only the root-element transformed?

Hi,

This is the first time I use SAX in order to translate my XML and I
encountered the following problem.

I use the following Java-code to produce xml that should be transformed
(Based on the xml that is created by the 'createXml()' several
underlying xml-files are merged together. The resulting xml seems to be
well-formed):
When I use the xsl-file, only the root element is transformed, resulting
in the output at the end of this message (blank lines are deleted).

Why are all the other elements ignored (If I write the xml and xsl to my
file-system and use Internet Exlorer to view the xml, the xml -s
transtlated as intended)?

Ben
public class XMLtoPDFtrans {
private Reader inputXml = null;
private String inputXsl;
private String blockDefLocation;

private SAXTransformerFactory saxTransFact;
private TransformerHandler transHand;

static Document document;
private TransformerFactory tf;

public XMLtoPDFtrans(String formName,
String[] formBlocks,
String formBlockDefLocation) {
if (formName == null || formBlocks ==null) {
System.out.println("Onvoldoende input");
System.exit(1);
}
blockDefLocation = formBlockDefLocation;
inputXml = createXml(formName, formBlocks);

tf = TransformerFactory.newInstance();
try {
// inputXsl = new
File("WEB-INF\\src\\minlnv\\pdf\\XML_to_PDF.xsl").toURL().to ExternalForm();
if (tf.getFeature(SAXTransformerFactory.FEATURE)) {
saxTransFact = (SAXTransformerFactory) tf;
transHand = null;
if (inputXsl == null) {
transHand = saxTransFact.newTransformerHandler();
} else {
transHand = saxTransFact.newTransformerHandler(
new StreamSource(inputXsl));
}
}
transHand.setResult( new StreamResult(System.out));
} catch (TransformerConfigurationException e) {
e.printStackTrace();
// } catch (MalformedURLException e) {
e.printStackTrace();
}
}

public StreamResult getStream() {
StreamResult result = null;
try {
InputSource xmlInputFile = new InputSource( inputXml);
SAXFormLezer saxFormLezer = new SAXFormLezer( blockDefLocation);

saxFormLezer.setContentHandler(transHand);
saxFormLezer.parse(xmlInputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
return result;
}

private Reader createXml(String form, String[] blocks) {
CharArrayWriter caw = new CharArrayWriter();
String opbouw = form;

AttributesImpl attribImpl = new AttributesImpl();
attribImpl.addAttribute("","bottomMargin","bottomM argin","float","50.0");
attribImpl.addAttribute("","leftMargin","leftMargi n","float","20.0");
attribImpl.addAttribute("","pageHeight","pageHeigh t","float","650.0");
attribImpl.addAttribute("","pageWidth","pageWidth" ,"float","300.0");
try {
DataWriter w = new DataWriter(caw);
w.startDocument();
w.startElement("","formulier","formulier",attribIm pl);
for (int tel = 0; tel <blocks.length; tel++) {
attribImpl = new AttributesImpl();
attribImpl.addAttribute("","naam","naam","String", blocks[tel]);
opbouw += blocks[ tel];
w.dataElement("","formBlock","formBlock", attribImpl,"");
}
w.dataElement("formClassName", opbouw);
w.endElement("","formulier","formulier");
w.endDocument();
} catch (SAXException e) {
e.printStackTrace();
}
return new CharArrayReader(caw.toCharArray());
}

Produced xml:
_____________

<?xml version="1.0" encoding="UTF-8"?><interim>
<formBlock blockHeight="650.0" blockName="A01">
<pageSeparator>true</pageSeparator>
<dataItemString posY="640.0" posX="202.0" substringBegin="2"
substringEnd="4">
<dataItem>
<dataId>1</dataId>
</dataItem>
</dataItemString>
<dataItemString posY="640.0" posX="257.0" substringBegin="2"
substringEnd="4">
<dataItem>
<dataId>71</dataId>
</dataItem>
</dataItemString>
<dataItemString posY="640.0" posX="312.0">
<dataItem>
<dataId>81</dataId>
</dataItem>
</dataItemString>

</formBlock>
<formClassName>eGDIA01</formClassName>
</interim>

xsl
____

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="formClassName" >
formClassName
<xsl:apply-templates />
</xsl:template>
<xsl:template match="/">
DataItem
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//pageSeparator" >
PageSep
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>

Output:
_________

DataItem
true
1
71
81
eGDIA01
Oct 5 '05 #1
0 952

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

Similar topics

1
by: Jayaprakash Rudraraju | last post by:
Hi, All php files in document root work fine. While php files in sub-directories of document root shows the php source like a text file. I have looked for help and also FAQ. Did I miss...
1
by: Krzysztof Kaczkowski | last post by:
Hello Im having problem, wxTreeCtrl generate 3 x EVT_TREE_SEL_CHANGED on click item right button mouse. This problem only win32. Why? Simple example: from wxPython.wx import * class...
2
by: Nicolas Favre-Félix | last post by:
Hello, I have a little problem using Tkinter: I'd like to make a interface with 3 labels on the left, facing with 3 Entry on the right, a button below Entrys, and a Listbox under all. I could...
2
by: pauline_neave | last post by:
Hi-ya, I want to be able to only allow root access while I dump the databases, thus locking out all non-root users ( even remote logins) then allow all normal users back in after the dump has been...
2
by: news.sbcglobal.net | last post by:
I hope I can explain this well enough to understand. I have a master page that is used by almost all of the pages in my site. On the master page is a table. In one of the cells in this table, I...
2
by: Fabrizio Pollastri | last post by:
My code is the following: from Tkinter import * def tk_dummy_call(*args): return root = Tk() # save call address
11
by: mp- | last post by:
I want to be able to allow people to check their email from my PHP online application. Given only the users 1) email address, 2) username (if applicable) and 3) password - how can I auto detect...
8
by: martinnorth | last post by:
Hi, I am running Python and MySQL on Ubuntu and have installed MySQLdb. If I try to import MySQLdb I get the following error: ActivePython 2.5.2.2 (ActiveState Software Inc.) based on Python...
4
by: jmDesktop | last post by:
I have searched everywhere and tried several things. I have a treeview with and want to be able to only select a parent node. For example: root //don't want to drag this -parent1 //yes, drag...
7
by: Amichai | last post by:
Hi All. I have an xml something like this: <?xml version="1.0" encoding="UTF-8"?> <root> <person> <name>John</name> <family name>Smith</family name> </person>
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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
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,...

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.