cbVision
06-11-2010, 03:55 PM
Greetings,
I'm just starting to learn how XML and XSL work together to create a page.
I have two files:
test.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<id>1</id>
<title>book 1</title>
<description>Description of book 1</description>
</row>
<row>
<id>2</id>
<title>book 2</title>
<description>Description of book 2</description>
</row>
</books>
test.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>What's New</h1>
<xsl:for-each select="books/row">
<h2><xsl:value-of select="title"/></h2>
<p><xsl:value-of select="description"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I open test.xml in the web browser, everything works great, it uses the XSL and creates a list of the XML rows.
Is it possible to include the output from the test.xml file in an XHTML built with PHP (I guess it would be a PHP page).
test.php
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<body>
<p>Just a random page on the website that wants to include the content generated from the XML file</p>
<?php include('test.xml'); ?>
</body>
</html>
Maybe I'm going about this the wrong way. The goal is to have several pages dynamically grab the content from the XML file and display it when the XML file is updated. The ideal method would be to pull the data from a database; however this is not an option in my situation. I figured I could just store the data in an XML file and pull it from there.
Any ideas?
Thanks!
I'm just starting to learn how XML and XSL work together to create a page.
I have two files:
test.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<id>1</id>
<title>book 1</title>
<description>Description of book 1</description>
</row>
<row>
<id>2</id>
<title>book 2</title>
<description>Description of book 2</description>
</row>
</books>
test.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>What's New</h1>
<xsl:for-each select="books/row">
<h2><xsl:value-of select="title"/></h2>
<p><xsl:value-of select="description"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I open test.xml in the web browser, everything works great, it uses the XSL and creates a list of the XML rows.
Is it possible to include the output from the test.xml file in an XHTML built with PHP (I guess it would be a PHP page).
test.php
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<body>
<p>Just a random page on the website that wants to include the content generated from the XML file</p>
<?php include('test.xml'); ?>
</body>
</html>
Maybe I'm going about this the wrong way. The goal is to have several pages dynamically grab the content from the XML file and display it when the XML file is updated. The ideal method would be to pull the data from a database; however this is not an option in my situation. I figured I could just store the data in an XML file and pull it from there.
Any ideas?
Thanks!