我需要使用XSLTProcessor将xml文档转换为html。如何使用XSL将XML转换为HTML?
我的XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<items>
<item>
<property title="title1"><![CDATA[data1]]></property>
<property title="title2"><![CDATA[data3]]></property>
<property title="title3"><![CDATA[data3]]></property>
</item>
<item>
<property title="title4"><![CDATA[data4]]></property>
<property title="title5"><![CDATA[data5]]></property>
<property title="title6"><![CDATA[data6]]></property>
</item>
</items>
我要得到的是:
<html>
<table border="1">
<tr bgcolor="#eee"><td colspan="2">title1: data1</td></tr>
<tr><td> title2</td> <td>data2</td></tr>
<tr><td> title3</td> <td>data3</td></tr>
<tr bgcolor="#eee"><td colspan="2">title4: data4</td></tr>
<tr><td> title5</td> <td>data5</td></tr>
<tr><td> title6</td> <td>data6</td></tr>
</table>
</html>
我的XSL文件现在是:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:php="http://php.net/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<xsl:apply-templates select="items"/>
</html>
</xsl:template>
<xsl:template match="items">
<table border="1">
<xsl:apply-templates select="item"/>
</table>
</xsl:template>
<xsl:template match="item">
<tr bgcolor="#eee"> <td colspan="2">
<xsl:value-of select="/descendant::*/@*"/>:
<xsl:value-of select="property"/>
</td> </tr>
</xsl:template>
</xsl:stylesheet>
但只返回第一个标签“属性”。我是xslt中的新成员,我该如何获取“property”标记列表?
谢谢,它的工作原理!) –