[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Troubles with SAX

Subject: Troubles with SAX
From: Miroslav Šimko <miroslav.simko@xxxxxxxxxx>
Date: Fri, 19 Mar 2004 08:59:10 +0100
streamresult sax
Hello,
I have troubles using SAX transform.
When transforming document without SAX, everything works fine. But when
using SAX, I get document without tags.
I dont know, where is the problem.
Thanks for any help.
Miro

----------------------------------------------------------------------------
------------------
first code

//without SAX, this works fine
TransformerFactory tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(new StreamSource("article.xsl"));
transformer.transform(new StreamSource("article.xml"), new StreamResult(new
FileOutputStream("article.html")));

----------------------------------------------------------------------------
------------------
second code

//using SAX, get troubles
File stylesheet = new File("article.xsl");
File datafile = new File("article.xml");

BufferedInputStream bis = new BufferedInputStream(new
FileInputStream(datafile));
InputSource input = new InputSource(bis);

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();

SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter filter = stf.newXMLFilter(new StreamSource(stylesheet));

filter.setParent(reader);

StreamResult result = new StreamResult(new
FileOutputStream("article.html"));

Transformer transformer = stf.newTransformer();
SAXSource transformSource = new SAXSource(filter, input);
transformer.transform(transformSource, result);

----------------------------------------------------------------------------
------------------
article.xml

<?xml version="1.0"?>
<Article>
<ArtHeader>
<Title>Title of my (Docbook) article</Title>
</ArtHeader>
<Sect1>
<Title>Title of Section 1.</Title>
<Para>This is a paragraph.</Para>
</Sect1>
</Article>

----------------------------------------------------------------------------
-------------------
article.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml"/>

<xsl:template match="Article">
<ARTICLE>
<xsl:apply-templates/>
</ARTICLE>
</xsl:template>

<xsl:template match="/Article/ArtHeader/Title">
<TITLE> <xsl:apply-templates/> </TITLE>
</xsl:template>

<xsl:template match="//Sect1">
<SECT><xsl:apply-templates/></SECT>
</xsl:template>

<xsl:template match="Para">
<PARA><xsl:apply-templates/></PARA>
</xsl:template>

</xsl:stylesheet>

----------------------------------------------------------------------------
---------------------------
get when using first code( this is what I want get)

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

<TITLE>Title of my (Docbook) article</TITLE>

<SECT>
Title of Section 1.
<PARA>This is a paragraph.</PARA>
</SECT>
</ARTICLE>

----------------------------------------------------------------------------
---------------------------
get when using second code( no tags in output)

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


Title of my (Docbook) article


Title of Section 1.
This is a paragraph.




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.