- XML
<?xml version="1.0" encoding="UTF-8"?>
//IE中直接查看XSL样式
<?xml-stylesheet type="text/xsl" href="C:/mytest/myaxis/WebContent/comments.xsl"?>
//webservice包体
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
//自定义默认命名空间http://www.com
<getCommentsResponse xmlns="http://www.com">
//结果为对象数组
<getCommentsReturn>
<anonymity>true</anonymity>
<commentId>1</commentId>
<commenter>王一</commenter>
//HTML标签
<content>匿名评论:)good!<img src='1.jpg' /></content>
<contentId>100</contentId>
</getCommentsReturn>
<getCommentsReturn>
<anonymity>false</anonymity>
<commentId>2</commentId>
<commenter>张三</commenter>
<content>署名评论:)good!<img src='2.jpg' /></content>
<contentId>100</contentId>
</getCommentsReturn>
</getCommentsResponse>
</soapenv:Body>
</soapenv:Envelope>
- XSL
<?xml version="1.0" encoding="UTF-8"?>
//定义所以命名空间
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.com">
//匹配包体
<xsl:template match="/soapenv:Envelope/soapenv:Body" >
<table border="1px #000000" >
<thead>
<tr>
<td>评论序号</td>
<td>评论者</td>
<td>内容</td>
</tr>
</thead>
<tbody>
//查找自定义默认命名空间http://www.com
//多条数据循环处理
<xsl:for-each select="p:getCommentsResponse/p:getCommentsReturn" >
<tr>
//取值显示
<td><xsl:value-of select="p:commentId"/></td>
<td>
//条件判断
<xsl:if test="p:anonymity = 'false' ">
<xsl:value-of select="p:commenter"/>
</xsl:if>
</td>
//HTML标签不做转化
<td><xsl:value-of select="p:content" disable-output-escaping="yes"/></td>
</tr>
</xsl:for-each>
</tbody>
<tfoot>
<tr>
<td align='left' colspan='3' >
//CDATA中数据不做转化
上一页<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>下一页
</td>
</tr>
</tfoot>
</table>
</xsl:template>
</xsl:stylesheet>
- XML调试工具
AltovaXMLspy