1

我正在尝试解析这个 XML

<ssa_admin_tablereports>
    <ssa_admin_tablereport_property name='ADM' value='&#10;Tables                  :0&#10;Partitions              : 0&#10;Files                   : 0&#10;Total size (Archive)    : 0&#10;Total size (Update)     : 0&#10;Total size (Arc/Upd)    : 0%/0%&#10;Total size              : 0&#10;Total rows              : 0&#10;Flat file size (Archive): 0&#10;Flat file size (Update) : 0&#10;Flat file size (Arc/Upd): 0%/0%&#10;Flat file size          : 0&#10;Compression ratio       : not defined&#10;'>
    </ssa_admin_tablereport_property>
    <ssa_admin_tablereport_property name='TORRENT' value='&#10;Tables                  : 53&#10;Partitions              : 97&#10;Files                   : 194&#10;Total size (Archive)    : 1980098&#10;Total size (Update)     : 586499&#10;Total size (Arc/Upd)    : 77% / 23%&#10;Total size              : 2566597&#10;Total rows              : 213404&#10;Flat file size (Archive): 9189418&#10;Flat file size (Update) : 6830067&#10;Flat file size (Arc/Upd): 57% / 43%&#10;Flat file size          : 16019485&#10;Compression ratio       : 84.0%&#10;'>
    </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 中相同的方式获得它呢?

4

1 回答 1

2

HTML 不允许 a tableinside a pre,但反过来应该没问题 - 尝试将preinside 放在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>
于 2013-10-21T14:05:52.783 回答