Java Reference
In-Depth Information
Object result = xpe.evaluate(doc, XPathConstants.NODESET);
NodeList nl = (NodeList) result;
for (int i = 0; i < nl.getLength(); i++)
System.out.println(nl.item(i).getNodeValue());
Caution Whenyouqualifyavariablenamewithanamespaceprefix(asin $ns:d ),
you must also register a namespace context to resolve the prefix.
Transforming XML Documents with XSLT
Extensible Stylesheet Language (XSL) is a family of languages for transforming and
formattingXMLdocuments. XSL Transformation (XSLT) istheXSLlanguagefortrans-
formingXMLdocumentstootherformats,suchasHTML(forpresentinganXMLdoc-
ument's content via a web browser).
XSLT accomplishes its work by using XSLT processors and stylesheets. An XSLT
processor is a software component that applies an XSLT stylesheet (an XML-based
template consisting of content and transformation instructions) to an input document
(without modifying the document), and copies the transformed result to a result tree ,
which can be output to a file or output stream, or even piped into another XSLT pro-
cessorforadditionaltransformations. Figure10-3 illustratesthetransformationprocess.
Figure 10-3. An XSLT processor transforms an XML input document into a result tree.
ThebeautyofXSLTisthatyoudon'tneedtodevelopcustomsoftwareapplications
toperformthetransformations.Instead,yousimplycreateanXSLTstylesheetandinput
it along with the XML document needing to be transformed to an XSLT processor.
ThissectionfirstintroducesyoutoJava'sXSLTAPI.Itthenpresentstwodemonstra-
tions of XSLT's usefulness.
Search WWH ::




Custom Search