Input and Output
XSLT processors, like other XML tools,
can read their input data from many different
sources. In the most basic scenario, you will load a static
stylesheet and XML document using the java.io.File
class.
More commonly, the XSLT stylesheet will come from a file, but the XML
data will be generated dynamically as the result of a database query.
In this case, it does not make sense to write the database query
results to an XML file and then parse it into the XSLT processor.
Instead, it is desirable to pipe the XML data directly into the
processor using SAX or DOM. In fact, we will even see how to read
nonXML data and transform it using XSLT.
System Identifiers, Files, and URLs
The simple examples presented earlier in this chapter introduced the
concept of a system identifier. As mentioned
before, system identifiers are nothing more than URIs and are used
frequently by XML tools. For example,
javax.xml.transform.Source
,
one
of the key interfaces in JAXP, has the following API:
public interface Source { String getSystemId( ); void setSystemId(String systemId); }
The second method, setSystemId( )
,
is crucial. By providing a URI to the Source
, the
XSLT processor can resolve URIs encountered in XSLT stylesheets. This
allows XSLT code like this to work:
<xsl:import href="commonFooter.xslt"/>
When it comes to XSLT programming, you will use
methods in java.io.File
and
java.net.URL
to convert platform-specific
file names into system IDs. These can then be used as parameters ...
Get Java and XSLT now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.