我正在尝试解析此XML
<ssa_admin_tablereports>
<ssa_admin_tablereport_property name='ADM' value=' Tables :0 Partitions : 0 Files : 0 Total size (Archive) : 0 Total size (Update) : 0 Total size (Arc/Upd) : 0%/0% Total size : 0 Total rows : 0 Flat file size (Archive): 0 Flat file size (Update) : 0 Flat file size (Arc/Upd): 0%/0% Flat file size : 0 Compression ratio : not defined '>
</ssa_admin_tablereport_property>
<ssa_admin_tablereport_property name='TORRENT' value=' Tables : 53 Partitions : 97 Files : 194 Total size (Archive) : 1980098 Total size (Update) : 586499 Total size (Arc/Upd) : 77% / 23% Total size : 2566597 Total rows : 213404 Flat file size (Archive): 9189418 Flat file size (Update) : 6830067 Flat file size (Arc/Upd): 57% / 43% Flat file size : 16019485 Compression ratio : 84.0% '>
</ssa_admin_tablereport_property>
</ssa_admin_tablereports>
用于此的XSLT是:
<pre><dd>
<table border="1">
<tbody>
<tr>
<th>Table Name</th>
<th>Table Report</th>
</tr>
<xsl:for-each select="ssa_admin_tablereports/ssa_admin_tablereport_property">
<tr>
<td valign="top"><xsl:value-of select="@name"/></td>
<td valign="top"><xsl:value-of select="@value"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</dd></pre>
但是当我使用浏览器打开XML文件时,值属性中的换行符和空格将被单个空格替换。那么我怎样才能以与XML相同的方式获得它?
答案 0 :(得分:2)
HTML不允许在table
内使用pre
,但反过来应该没问题 - 尝试将pre
放在td
内:
<xsl:for-each select="ssa_admin_tablereports/ssa_admin_tablereport_property">
<tr>
<td valign="top"><xsl:value-of select="@name"/></td>
<td valign="top"><pre><xsl:value-of select="@value"/></pre></td>
</tr>
</xsl:for-each>