[英]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.