新手问个问题:关于xsl显示xml内容?
新手问个问题,关于xsl显示xml内容
XML格式如下:
<Shares>
<Name> C$ </Name>
<Type> Special share (IPC$ or ADMIN$) for remote admin </Type>
<Name> 002 </Name>
<Type> Disk drive </Type>
<Name> 003 </Name>
<Type> Memory </Type>
</Shares>
xsl怎么写可以让他以table的格式展现?
Shares
<blockquote>
<table border= "1 " cellpadding= "0 " cellspacing= "0 " width= "500 ">
<tr align= "center ">
<th width= "100 "> Name </th>
<th width= "400 "> Type </th>
</tr>
<xsl:for-each select= "Shares ">
<tr align= "center ">
<td> <xsl:value-of select= "./Name "/> </td>
<td> <xsl:value-of select= "./Type "/> </td>
</tr>
</xsl:for-each>
</table>
</blockquote>
我这样写只能出来第一个,第二个不出来,怎么操作呢?
虽然可以通过在Name和Type中添加比如Share的tag来处理,然后在 <xsl:for-each select= "Shares/Share "> 即可操作,但如果就按照这个方式怎么操作?谢谢
[解决办法]
<xsl:for-each select= "//Name ">
<tr align= "center ">
<td> <xsl:value-of select= ". "> </td>
<td> <xsl:value-of select= "following-sibling::*[1] "/> </td>
</tr>
</xsl:for-each>
[解决办法]
xml:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<?xml-stylesheet type= 'text/xsl ' href= 'sample.xsl '?>
<User>
<User> mikel </User>
<Age> 11 </Age>
<User> yizi </User>
<Age> 12 </Age>
<User> t-bag </User>
<Age> 13 </Age>
</User>