[英]How do I transform a XML file into HTML using XSLT in PHP?
[英]How do I get my XSLT to open HTML/PHP and accept an entire XML node rowset?
到目前为止,当我单击超链接中嵌入的XSLT时,就会得到所需的页面。 但是,这也是我需要帮助的地方! 我需要我的style_sheet将整个row.node结果作为参数或数组onclick传递,以便我可以通过html进行嵌入和操作,以进行结果页面调用。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="property_resi.xsl"?>
<rows>
<row>
<ListingPrice>124000.00</ListingPrice>
<ListingRid>59999991</ListingRid>
<Status>Active</Status>
<StatusComments></StatusComments>
<StatusDate>2007-07-24T00:00:00</StatusDate>
<Stories>1.00</Stories>
<StreetDirection>East</StreetDirection>
<StreetName>San Sircettia</StreetName>
<StreetNumber>410</StreetNumber>
<StreetNumberModifier></StreetNumberModifier>
<StreetPostDirection></StreetPostDirection>
<StreetSuffix>St</StreetSuffix>
<YearBuilt>1999</YearBuilt>
<ZipCode>99999</ZipCode>
</row>
<row>
<ListingPrice>98000.00</ListingPrice>
<ListingRid>59999992</ListingRid>
<Status>Active</Status>
<StatusComments></StatusComments>
<StatusDate>2007-07-24T00:00:00</StatusDate>
<Stories>1.00</Stories>
<StreetDirection>South</StreetDirection>
<StreetName>Tuscany</StreetName>
<StreetNumber>560</StreetNumber>
<StreetNumberModifier></StreetNumberModifier>
<StreetPostDirection></StreetPostDirection>
<StreetSuffix>Circle</StreetSuffix>
<YearBuilt>2000</YearBuilt>
<ZipCode>99999</ZipCode>
</row>
<row>
<ListingPrice>805000.00</ListingPrice>
<ListingRid>59999993</ListingRid>
<Status>Active</Status>
<StatusComments></StatusComments>
<StatusDate>2007-07-24T00:00:00</StatusDate>
<Stories>1.00</Stories>
<StreetDirection>West</StreetDirection>
<StreetName>Hill View Park</StreetName>
<StreetNumber>2205</StreetNumber>
<StreetNumberModifier></StreetNumberModifier>
<StreetPostDirection></StreetPostDirection>
<StreetSuffix>Drive</StreetSuffix>
<YearBuilt>1978</YearBuilt>
<ZipCode>99999</ZipCode>
</row>
</rows>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:template match="/">
<html>
<body>
<h2>Current Listings</h2>
<table border="1">
<tr bgcolor="#9acd32"> </tr>
<xsl:for-each select="rows/row">
<xsl:sort select="City"/>
<xsl:sort select="ZipCode"/>
<tr> <td><a href="property_resi_xslt.html">
<xsl:value-of-select=
"concat(StreetNumber, ' ',
StreetDirection, ' ',
StreetName, ' ',
StreetSuffix, ' - ', City,
',', ZipCode, ' - ', '$',
ListingPrice)"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" `"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Lang" content="en" />
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<meta name="author" content="" />
<meta http-equiv="Reply-to" content="@.com" />
<meta name="generator" content="PhpED 8.0" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="creation-date" content="06/09/2012" />
<meta name="revisit-after" content="15 days" />
<title>Results page</title>
</head>
<body>
Insert & Manipulate`code here` My XML RESULTS HERE!!!!
</body>
</html>
您正在使用XML和XSLT在浏览器中生成HTML,但是当浏览器运行并显示HTML时,它将不再引用原始XML文档。 因此,它并没有真正传递“ row.node结果作为参数”。 您将必须确保将行集中的数据以某种方式放置在HTML文档中,然后可以将其传递到PHP页面。
您在评论中给出了这个例子
<a href="property_resi_xslt_test.php?ListingRid=$ListingRid;"><xsl:value-of select="concat(StreetNumber,' ', StreetDirection, ' ',StreetName, ' ', StreetSuffix, ' - ', City, ',', ZipCode, ' - ','$', ListingPrice)"/></a>
因此,您实际上已经处于正确的位置。 我假设$ ListingRid是您设置的包含ListingRid元素值的变量 。 您实际上想要的语法是这样
<a href="property_resi_xslt_test.php?ListingRid={$ListingRid}">
这称为“属性值模板”。 花括号指示它是要评估的表达式,而不是要从字面上输出的内容。
假设您当前的上下文是一个行元素,那么您实际上并不需要一个变量,您可以这样做
<a href="property_resi_xslt_test.php?ListingRid={ListingRid}">
而且,如果您想传回多个值,则可以在表达式中使用多个AVT
<a href="property_resi_xslt_test.php?ListingRid={ListingRid}&Status={Status}&ZipCode={ZipCode}">
当然,您在PHP页面中要做的是一个完全不同的问题。 这只是向您展示了如何首先将值传递给PHP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.