我想創建一個html頁面,顯示在谷歌地圖上的personell。要在地圖上創建不同的標記,我有一個javascript,它爲陣列位置中的每個條目創建一個標記。這個數組應該填充來自數據庫的數據(在xml中),並且必須轉換成我的html。使用範圍內的應用程序模板
請把我的XSL一起來看看:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB1tbIAqN0XqcgTR1-FxYoVTVq6Is6lD98&sensor=false"></script>
<script type="text/javascript">
var infos = [];
var locations = [
<xsl:apply-templates select='//rows'/>
];
function initialize() {
var myOptions = {
center: new google.maps.LatLng(50.59, 4.35),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("default"),myOptions);
setMarkers(map,locations)
}
function setMarkers(map,locations){
var marker, i
for (i = 0; i < locations.length; i++)
{ var name = locations[i][0]
var long = locations[i][1]
var lat = locations[i][2]
var contentmarker = locations[i][3]
latlngset = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
map: map, title: name , position: latlngset
});
map.setCenter(marker.getPosition())
var content = contentmarker
var infowindow = new google.maps.InfoWindow()
google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
return function() {
/* close the previous info-window */
closeInfos();
infowindow.setContent(content);
infowindow.open(map,marker);
/* keep the handle, in order to close it on next click event */
infos[0]=infowindow;
};
})(marker,content,infowindow));
}
}
function closeInfos(){
if(infos.length > 0){
/* detach the info-window from the marker ... undocumented in the API docs */
infos[0].set("marker", null);
/* and close it */
infos[0].close();
/* blank the array */
infos.length = 0;
}
}
</script>
</head>
<body onload="initialize()">
<div id="default" style="width:100%; height:100%"></div>
</body>
</html>
</xsl:template>
<xsl:template match='rows'>
<xsl:for-each-group select='row' group-by='@SiteNr'>
['<xsl:value-of select='@SiteName'/>', '<xsl:value-of select='@LON_R'/>', '<xsl:value-of select='@LAT_R'/>
', '<b><xsl:value-of select='@RegionName'/></b><br>Details (<xsl:value-of select='@SiteNr'/>):
<table border='1'>
<tr>
<th>PersNr</th>
<th>Name</th>
<th>Firstname</th>
<th>DeptNr</th>
<th>DeptName</th>
<th>PostNr</th>
</tr>
<xsl:for-each select="current-group()">
<xsl:apply-templates select="."/>
<tr>
<td><xsl:value-of select="@PersNr"/></td>
<td><xsl:value-of select="@Name"/></td>
<td><xsl:value-of select="@FirstName"/></td>
<td><xsl:value-of select="@DeptCode"/></td>
<td><xsl:value-of select="@DeptName"/></td>
<td><xsl:value-of select="@PostNr"/></td>
</tr>
</xsl:for-each>
<tr>
<td colspan='5'>TOTAAL</td>
<td align='center'><xsl:value-of select="(count(current-group()/@PersNr))"/></td>
</tr>
</table>']
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
如果我嘗試CDATA周圍的腳本,它運行,但我的腳本標記與<和>轉化和腳本好好嘗試一下再工作。
提取物我的xml:
<rows>
<row PersNr="B15975" Name="Vandendriessche" Firstname="Rudolf" DeptCode"J20100" DeptName="HR" Post="1230" RegionNum="3" RegionName="Plateau Berlaar" SiteNum="11002D" SiteName="KW BELGIELEI" LON_kw="4.418" LAT_kw="51.205" />
我是新來的XSL/HTML/JavaScript的,所以如果你知道答案,請大家幫我,有一些額外的信息(如果你能提供的話)。
你能出多一點的XSLT,而不只是截斷它在中間(特別是相匹配** **行並遵循XSL的JavaScript模板:申請-templates)。此外,顯示您的輸入XML可能會有所幫助。謝謝! –