[ Pobierz całość w formacie PDF ]

a SAXTransformerFactory. So, to get at the extra methods defined by SAXTransformerFactory, the return value
must be cast to the actual type.
2. An XMLFilter object is both a SAX reader and a SAX content handler. As a SAX reader, it generates SAX
events to whatever object has registered to receive them. As a content handler, it consumes SAX events
generated by it's "parent" object -- which is, of necessity, a SAX reader, as well. (Calling the event generator a
"parent" must make sense when looking at the internal architecture. From the external perspective, the name
doesn't appear to be particularly fitting.) The fact that filters both generate and consume SAX events allows them
to be chained together.
Understanding How it Works
The code listed above shows you how to set up the transformation. The diagram below should help you get a better feel for what's
happening when it executes.
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/5_chain.html (3 of 6) [8/22/2001 12:52:47 PM]
5. Chaining Transformations
When you create the transformer, you pass it at a SAXSource object, which encapsulates a reader (in this case, filter2) and an
input stream. You also pass it a pointer to the result stream, where it directs its output. The diagram shows what happens when you
invoke transform() on the transformer. Here is an explanation of the steps:
1. The transformer sets up an internal object as the content handler for filter2, and tells it to parse the input source.
2. filter2, in turn, sets itself up as the content handler for filter1, and tells it to parse the input source.
3. Continuing to pass the buck, filter1 asks the parser object to please parse the input source.
4. The parser does so, generating SAX events which it passes to filter1.
5. filter1, acting in its capacity as a content handler, processes the events and does its transformations. Then, acting in its
capacity as a SAX reader (XMLReader), it sends SAX events to filter2.
6. filter2 does the same, sending its events to the transformer's content handler, which generates the output stream.
Testing the Program
To try out the program, you'll create an XML file based on a tiny fraction of the XML DocBook format, and convert it to the
ARTICLE format defined here. Then you'll apply the ARTICLE stylesheet to generate an HTML version.
Note:
This example processes small-docbook-article.xml using docbookToArticle.xsl, and article1c.xsl. The result is the
HTML code shown in filterout.txt. (The browser-displayable versions are small-docbook-article-xml.html,
docbookToArticle-xsl.html, article1c-xsl.html, and filterout.html.) See the O'Reilly web pages for a good description of
the DocBook article format.
Start by creating a small article that uses a minute subset of the XML DocBook format:
Title of my (Docbook) article
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/5_chain.html (4 of 6) [8/22/2001 12:52:47 PM]
5. Chaining Transformations
Title of Section 1.
This is a paragraph.
Next, create a stylesheet to convert it into the ARTICLE format:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
(see Note #1)
(see Note #2)
(see Note #3)
(see Note #4)
(see Note #5)
Notes:
1. This time, the stylesheet is generating XML output.
2. The element below matches the main title. For section titles, the tag gets stripped. (Since no template conversion
governs those title elements, they are ignored. The text nodes they contain, however, are still echoed as a result
of XSLT's built in template rules (more on that below).
3. The title from the DocBook article header becomes the ARTICLE title.
4. Numbered section tags are converted to plain SECT tags.
5. Carries out a case conversion, so Para becomes PARA.
Although it hasn't been mentioned explicitly, XSLT defines a number of built-in (default) template rules. The complete set is listed in
Section 5.8 of the spec. Mainly, they provide for the automatic copying of text and attribute nodes, and for skipping comments and
processing instructions. They also dictate that inner elements are processed, even when their containing tags that don't have templates.
That is the reason that the text node in the section title is processed, even though the section title is not covered by any template.
Now, run the FilterChain program, passing it the stylesheet above, the ARTICLE stylesheet, and the small DocBook file, in that order.
The result should like this:
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/5_chain.html (5 of 6) [8/22/2001 12:52:47 PM]
5. Chaining Transformations
Title of my (Docbook) article
Title of Section 1.
This is a paragraph.
Conclusion
Congratulations! You have completed the XSLT tutorial! There is a lot you do with XML and XSLT, and you are now prepared to
explore the many exciting possibilities that await.
Top Contents Index Glossary
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/5_chain.html (6 of 6) [8/22/2001 12:52:47 PM]
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideshow1a-dtd.html
DTD for a simple "slide show".
-->
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideshow1a-dtd.html [8/22/2001 12:52:49 PM]
Wake up to WonderWidgets!
Why WonderWidgets are great Who buys WonderWidgets Market Size
Penetration Expected Revenues Profit Margin First we fozzle the frobmorten Then we framboze the
staten Finally, we frenzle the fuznaten ^ | | = fozzle V | = framboze staten--------------------+
= frenzle ]]>
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/samples/slideSample05.xml [8/22/2001 12:52:49 PM] [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • uchidachi.htw.pl