Architecture mode in the web development framework (3)

zhaozj2021-02-16  56

Page content and style separation, (XSLT)

The first step of page content and style separation is the separation of the CSS style file and the HTML page, but HTML's page content and display elements are tiered together. After XML promotion, XSLT is also large, and it is widely used in a web distribution system. The ASP.NET and JAVA Web framework are walking in this direction, just the Java web framework is faster, farther. The description will be described below.

When processing XSLT, the SAX interface is much faster than the DOM interface, and hardly occupies memory space. The disturbing is that the .NET framework has not yet available in the SAX interface. Microsoft provides a set of MSXML SDK, which contains SAX implementations based on COM components and provides an example in VB and VC. In the VC case of MSXML SAX, you need to include the header file MSXML2.H. That is to say, the .NET framework cannot call MSXML SAX in a natural way. Also, how the .NET framework is implemented, ie, system.xml.xsl.xsltransform uses what way is implemented, call the SAX interface, or the DOM interface. How to use the .NET framework into a XSLT processing pipeline? I can't find a way. There is no example in this regard.

The Apache Xerce project supports XML processing, providing Java and C versions, and provides a package that calls MSXML; Apache Xalan project supports XSLT processing; Apache Cocoon 2.0, uses SAX interface to form an XSLT processing pipe.

An example of an Apache Xalan Project UsesexmlFilters.java

Usexmlfilters.java. (8), file header omitted)

Public Class UseXmlFilters

{

Public static void main (string [] args)

THROWS TRANSFORMEREXCETION, TRANSFORMERCONFIGURATIONEXCEPTION,

SAXEXCEPTION, IOEXCEPTION

{

// instantiate a transformerfactory.

TransformerFactory Tfactory = TransformerFactory.newInstance ();

// DETERMINE WHENER THE TRENSFORMERFACTORY Supports the USE UF SAXSOURCE

// and SaxResult

IF (TFactory.Feature) && TFactory.getFeature (SaxResult.Feature))

{

// Cast The TransformerFactory to SaxtransformerFactory.

SaxTransformerFactory SaxtFactory = (SaxtransformerFactory) TFactory;

// Create an XMLFilter for Each Stylesheet.

XMLFilter XMLFilter1 = saxtfactory.newxmlfilter (New StreamSource ("foo1.xsl"));

XMLFilter XMLFilter2 = saxtfactory.newxmlfilter (New StreamSource ("foo2.xsl");

XMLFilter XMLFilter3 = saxtfactory.newxmlfilter ("foo3.xsl"); // Create An XmlReader.

XmlReader Reader = XmlReaderFactory.createxmlReader ();

// xmlfilter1 Uses The XmlReader As ITS Reader.

XMLFilter1.SetParent (Reader);

// xmlfilter2 Uses XMLFilter1 As ITS Reader.

XMLFilter2.SetParent (XMLFilter1);

// xmlfilter3 Uses XMLFilter2 As ITS Reader.

XMLFilter3.SETPARENT (XMLFilter2);

// Xmlfilter3 Outputs Sax Events to the Serializer.

Serializer Serializer = SerializerFactory.getSerializer

(OutputProperties.GetDefaultMethodproperties);

Serializer.SetOutputStream (System.out);

XMLFilter3.SetContentHandler (Serializer.ascontentHandler ());

// Perform The Series of Transformations As Follows:

// - Transformer3 gets its parent (transformer2) as the xmlreader / xmlfilter

// and calls transformer2.parse (New InputSource ("foo.xml")).

// - Transformer2 gets its parent (transformer1) as the xmlreader / xmlfilter

// and calls transformer1.parse (New INPUTSOURCE ("foo.xml")).

// - Transformer1 Gets ITS Parent (Reader, A Saxparser) as the xmlreader

// and calls reader.parse (New INPUTSOURCE ("foo.xml")).

// - Reader Parses The Xml Document and Sends The Sax Parse Events To Transformer1,

// Which Performs Transformation 1 and sends the output to transformer2.

// - Transformer2 Parses The Transformation 1 Output, Performs Transformation 2, And

// sends the output to transformer3.

// - Transformer3 Parses The Transformation 2 Output, Performs Transformation 3,

// and sends the output to the serializer.

XMLFilter3.Parse (New InputSource ("foo.xml");

}

}

}

APACHE COCOON project example SiteMap.xmap

The SiteMap.xMap of the Apache Cocoon project defines the XSLT processing pipe. See the section in the following example, the error message has passed the XSLT processing, "Error2Document.xsl" and "Apache.xsl". /sample/tutorial/sitemap.xmap (80s, unrelated part omit)

...

...

...

ASP.NET XML web control example

The following example is extracted from the .NET framework text, explaining how to use an XML control to display the sample XML file by the sample XSL conversion file. The sample XML file is named people.xml, the sample XSL conversion file name is peopleTable. XSL. It can be seen that ASP: XML is only one step XSLT conversion.

XML EXAMPLE

Documentsource = "people.xml"

Transformsource = "peopletable.xsl"

Runat = "server" />

转载请注明原文地址:https://www.9cbs.com/read-23536.html

New Post(0)