1
我需要一些幫助,使用XSLT將XML文件轉換爲HTML。我遇到的問題是for-each循環被跳過。解析器在「x:imagelist」下找不到任何「文件」元素。我究竟做錯了什麼?我已經嘗試過其他帖子的建議,但沒有任何運氣。使用XSLT將XML轉換爲HTML
這裏是XML源文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<x:imagelist xmlns:x="ext:extractor">
<file>
<fileName>2012-04-28 16</fileName>
<format>jpg</format>
<width>3264</width>
<height>1840</height>
<dateTime>Sat Apr 28 16:49:22 CEST 2012</dateTime>
<cameraModel>HTC, HTC One X</cameraModel>
<ISO>100</ISO>
<exposure>8.0E-4</exposure>
<fStop>F2</fStop>
</file>
<file>
<fileName>2012-04-28 16</fileName>
<format>jpg</format>
<width>3264</width>
<height>1840</height>
<dateTime>Sat Apr 28 16:49:24 CEST 2012</dateTime>
<cameraModel>HTC, HTC One X</cameraModel>
<ISO>100</ISO>
<exposure>8.0E-4</exposure>
<fStop>F2</fStop>
</file>
<file>
<fileName>2012-04-28 16</fileName>
<format>jpg</format>
<width>3264</width>
<height>1840</height>
<dateTime>Sat Apr 28 16:49:32 CEST 2012</dateTime>
<cameraModel>HTC, HTC One X</cameraModel>
<ISO>100</ISO>
<exposure>6.0E-4</exposure>
<fStop>F2</fStop>
</file>
<location>C:\Users\Serban\Documents\pics</location>
</x:imagelist>
這裏是XSL文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://something//x">
<xsl:template match="/">
<html>
<head>
<title>My Images</title>
<link rel="stylesheet" type="text/css" href="style_light.css"></link>
</head>
<body>
<div class="everything">
<div class="headerDiv">
<h1>MY IMAGES</h1>
<h3>View your image list online!</h3>
</div>
<div class="contentDiv">
<table class="dataTable">
<tr class="tableHeader">
<th>File Name</th><th>Format</th><th>Width</th><th>Height</th><th>Date and Time</th><th>Camera Model</th><th>ISO</th><th>Exposure</th><th>F-Stop</th>
</tr>
<xsl:for-each select="x:imagelist/file">
<tr>
<td><xsl:value-of select="fileName"></xsl:value-of></td>
<td><xsl:value-of select="format"></xsl:value-of></td>
<td><xsl:value-of select="width"></xsl:value-of></td>
<td><xsl:value-of select="height"></xsl:value-of></td>
<td><xsl:value-of select="dateTime"></xsl:value-of></td>
<td><xsl:value-of select="cameraModel"></xsl:value-of></td>
<td><xsl:value-of select="ISO"></xsl:value-of></td>
<td><xsl:value-of select="exposure"></xsl:value-of></td>
<td><xsl:value-of select="fStop"></xsl:value-of></td>
</tr>
</xsl:for-each>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
輝煌,那工作,非常感謝你! – Serban
我想我仍然需要關於XML名稱空間的一些教訓... – Serban