A xslt sample

zhaozj2021-02-16  58

A xslt sample

WANG Hailong

In the Chinese website, I saw a lot of examples of XSLT, but most of them were entry nature. An example of an XSLT is given below, indicating some of the typical usage of XSLT.

The XSLT1.0 specification defines the Document () function, providing the initial handling of multiple XML input files. We use this feature to achieve the new old XML file comparison.

For example, we have an XML format product list listing some of the Open Source software for XSLT processing.

Every time, we update a list of products.

The following product.1.xml is the first product list.

Product.1.xml

>>

001

Apache Xalan Xslt

http://xml.apache.org/xalan-j/

002

saxon xslt

http://saxon.sourceforge.net/

After a while, the product list is updated to product.2.xml. Among them, the product list previous product list --Product.1.xml.

Product.2.xml

Product.1.xml

001

Apache Xalan Xslt

http://xml.apache.org/xalan-j/

002

saxon xslt

http://saxon.sourceforge.net/

003

XT XSLT

http://www.4xt.org/

004

Oasis Xslt http://www.oasis-open.org/

We handle product.2.xml with the XSL file below to find new adds.

Product.diff.xsl

Although this XSL file is short, it includes a very important feature of XSLT and XPath's typical usage. Because the content of Product-History is Product.1.xml, Document (Product-History) gets the root element of the last product list product.1.xml.

Document (Product-History) // Product obtains all Product elements below the root element of Product.1.xml. We can also write document / product, which is more confirmed, specifying only the Product-root elements below the product.

Note that Product [NOT (Product-ID = History / Product-id)] indicates "Product-id and History Product-id, which is different"; Product [Product-ID! = History / Product-ID] "Product-id and History Product-ID have at least one different product".

The processed XML results are as follows.

003

XT XSLT

http://www.4xt.org/

004

Oasis Xslt http://www.oasis-open.org/

About how to run this example or other XSLT example. First, you need an XSLT conversion tool. Where do I get XSLT conversion tools? See the product list product list Product.2.xml, including a good XSLT conversion tool. Access the URL inside. :-)

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

New Post(0)