RE: [xsl] Troubles with SAX

Subject: RE: [xsl] Troubles with SAX
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 19 Mar 2004 08:55:21 -0000
The instruction

Transformer transformer = stf.newTransformer()

creates an identity transformer, which does not use your stylesheet as
input.

Take a look at the JAXP sample applications issued with Xalan or Saxon. You
seem to have completely misunderstood the purpose of newXMLFilter.

Michael Kay 

# -----Original Message-----
# From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
# [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
# Miroslav Šimko
# Sent: 19 March 2004 07:59
# To: Mulberry Mailing list
# Subject: [xsl] Troubles with 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
# 
# 


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


Current Thread