Home  >  Article  >  Backend Development  >  Use xml and xsl to create web page examples

Use xml and xsl to create web page examples

黄舟
黄舟Original
2017-02-15 15:58:122443browse

Reprinted, please indicate the source: Use xml and XSL to make webpage instances

Use XML and XSL as a web page. Just save the two files and run them.

cdcatalog.xml is equivalent to html
cdcatalog.xsl is equivalent to css



cdcatalog.xml

[html] view plaincopy

<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="http://www.php1.cn/">
 
<catalog> 
  <cd> 
    <title>Empire Burlesque</title> 
    <artist>Bob Dylan</artist> 
    <country>USA</country> 
    <company>Columbia</company> 
    <price>10.90</price> 
    <year>1985</year> 
  </cd> 
 <cd> 
    <title>Empire Burlesqu2e</title> 
    <artist>Bob Dyla2n</artist> 
    <country>USA2</country> 
    <company>Columbia2</company> 
    <price>10.91</price> 
    <year>1983</year> 
  </cd> <cd> 
    <title>Empire Burlesqu2e</title> 
    <artist>Bob Dyla2n</artist> 
    <country>USA2</country> 
    <company>Columbia2</company> 
    <price>10.91</price> 
    <year>1983</year> 
  </cd> <cd> 
    <title>Empire Burlesqu2e</title> 
    <artist>Bob Dyla2n</artist> 
    <country>USA2</country> 
    <company>Columbia2</company> 
    <price>10.91</price> 
    <year>1983</year> 
  </cd> <cd> 
    <title>Empire Burlesqu2e</title> 
    <artist>Bob Dyla2n</artist> 
    <country>USA2</country> 
    <company>Columbia2</company> 
    <price>10.91</price> 
    <year>1983</year> 
  </cd> <cd> 
    <title>Empire Burlesqu2e</title> 
    <artist>Bob Dyla2n</artist> 
    <country>USA2</country> 
    <company>Columbia2</company> 
    <price>10.91</price> 
    <year>1983</year> 
  </cd> 
</catalog>





cdcatalog.xsl

[html] view plaincopy

<?xml version="1.0" encoding="ISO-8859-1"?> 
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
 
<xsl:template match="/"> 
  <html> 
  <body> 
    <h2>My CD Collection</h2> 
    <table border="1"> 
    <tr bgcolor="#9acd32"> 
      <th align="left">Title</th> 
      <th align="left">Artist</th> 
    </tr> 
    <xsl:for-each select="catalog/cd"> 
    <tr> 
      <td><xsl:value-of select="title"/></td> 
      <td><xsl:value-of select="artist"/></td> 
    </tr> 
    </xsl:for-each> 
    </table> 
  </body> 
  </html> 
</xsl:template> 
 
</xsl:stylesheet>





Open cdcatalog.xml with a browser to see the effect. Supported by most browsers and programming languages.

Effect:

My CD Collection

Title Artist
Empire Burlesque Bob Dylan
Empire Burlesqu2e Bob Dyla2n
Empire Burlesqu2e Bob Dyla2n
Empire Burlesqu2e Bob Dyla2n
Empire Burlesqu2e Bob Dyla2n
Empire Burlesqu2e Bob Dyla2n

The above is the content of using xml and xsl to make web page examples. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:xml——jsonNext article:xml——json