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

My first try at XSL..can someone give me a few pointer

Subject: My first try at XSL..can someone give me a few pointers?
From: "Kevin Duffey" <kevin.duffey@xxxxxxxx>
Date: Sun, 7 Jan 2001 15:17:55 -0800
my first try
Hi there,

Just joined this list in hopes to figure out a few things. First..what is a
recommended XSL book? I see a few that are coming out soon, but is there a
good one right now that explains the full syntax of XSL and XPATH? Also,
being that I am using Xalan (the latest build as of three days ago), it
supports something called TrAX, which I am trying to use to convert..it is a
Java API or something and right now I seem to be using only 4 lines of code.
I pass in two StreamSources, one of which is XML, and the other of which is
XSL. I don't know if how I am doing this is correct or not, but here is a
very basic XML file I have, and the XSL I am using to convert it to HTML. If
someone could just let me know if this should work or not that would be
great. I keep getting an error saying the XML file needs to have a root
element, and I am not sure what it is saying.

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<OrderBuilder>
  <Name>HELLO</Name>
</OrderBuilder>


XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

  <xsl:template match="OrderBuilder">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

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

</xsl:stylesheet>


Lastly, what I am trying to do is something like the cocoon project, but
much smaller in size. I have a working, very simple mvc framework using a
singel controller servlet and a few other helper classes. It is similar to
Struts, but much smaller in size and a little bit different. I added an
xslControllerServlet, which instead of forwarding to a JSP page, it grabs
the output of the JSP page (which results in XML well-formed..I think), and
applies an XSL to it, to transform it. Here is the last bit of code, but I
can supply the whole thing if necessary. I don't want anyone to do the whole
thing for me..I just want to know if what I read from the XSL stuff online
if what I am doing should work, or am I way off the mark here. From what I
gathered, the TrAX api is supposed to make the process very simple..simply
supply the xml stream and xsl stream, and the result is put in the output
stream you supply. Here is the code snippet.

      String urlPrefix = "http://localhost/";
      URL url = new URL(urlPrefix + "xsl/demo.jsp");
      HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
      InputStream is = urlConnection.getInputStream();
      xmlStream = new StreamSource(is);
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer(xslStream);
      transformer.transform(xmlStream, new
StreamResult(response.getOutputStream()));

That above is the portion that grabs the JSP page output (as if a web
browser accessed it so that I can dynamically create the XML output it
returns), and then calls the TrAX api transform() method with the xmlStream
and uses the HttpServletResponse outputstream for the output.

I set the response.setContentType() to the xsl output (which in my case
right now..is always HTML). I should ask..do I need to do a response.flush()
call or anything..or should the above work and send the transformed output
to the browser that requested the initial page?


Thanks for any help. While not a big deal..if anyone would like my simple
mvc framework with source, I am happy to give it out. A few things it
does..much like Struts, is supports auto-bean population, a single xml
config file mapping for all actions (and multiple forwards per action, each
forward having the ability to specify an XSL page to use to transform it;
the auto-population actually works on nested objects, so that if you have a
JavaBean with an object in it as a field, you can auto-populate that object
(and nested objects, etc), which allows you to use "pass-through" abilities
(ask for more details if you would like). It also uses reflection to make it
very easy to know what action method is being called on any page (or any
button that submits a form or any href link).

Anyways..thanks for any help.




 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.