XSLT is a language used to convert XML document structures. it is short for EXtensibleStyleLanguageExtensionsTransformations. 1. Introduction
XSLT is a Language used to convert XML document structures. it is short for EXtensible Style Language Extensions Transformations.
XSLT is similar to CSS in HTML, but it is more powerful than CSS.
According to the W3C specification, the earliest design of XSLT is to help convert XML documents into other documents.
However, as the application goes deeper, XSLT is not only used to convert XML into HTML or other document formats, but also to convert XML document structures.
The elements and attributes of XSLT provide a declaration for processing XML data. you can use XSLT words to extract content from other documents and create new elements and attributes, in more cases, the two methods are organically combined.
XSLT 1.0 conversion requires two operation files (XML source file and XSLT style sheet file) to generate a result document.
In the new XSLT 2.0 standard, the two can be combined.
Using XSLT, you can match each element and its attributes with HTML or XHTML to display and output the document content correctly.
An XSLT style sheet is a correct and valid XML document in XML format, and its extension is. xsl.
The syntax for using XSLT style sheets in XML documents is as follows:
2. use XSLT to convert XML applications
In this example, the XSLT extensible style is used to convert an XML file to a file in another format before output.
In this example, XML is converted using XSLT, and the data in the XML file after XSLT style conversion is output.
First, declare the XML file and specify the document as an XML file.
Note that the XSLT style sheet itself is an XML document, so it also complies with the XML document rules.
Then declare the XSLT style sheet and the prefix of the XSLT namespace (xsl: stylesheet ).
The XSLT namespace prefix can be written in two ways: xsl: stylesheet and xsl: transform.
Its meaning and function are exactly the same, but the former is more commonly used. Specify the XSLT namespace through the xmlns: xsl attribute.
Then define the template rules. here we use the xsl: template element for encapsulation. The Math attribute specifies a mode to describe the input that the rule matches.
Finally, convert the XML document.
Code 3
1. the code for creating the cdcatalog. xsl file is as follows:
My CD Collection
2. the code for creating cdcatalog. xml is as follows:
Empire BurlesqueBob Dylan
USA
Columbia
10.90
1985
Hide your heartBonnie Tyler
UK
CBS Records
9.90
1988
IV. running results
The preceding section describes how to use XSLT to convert the sample code of XML. For more information, see other related articles in the first PHP community!