消息关闭
    暂无新消息!

怎么用xslt的格式解析xml

问题作者 : 大奔KY2017-06-22发布
git_log.xml 如下,怎么用xslt的格式解析git_log.xml,然后能在网页上显示,请大神支招,谢谢

<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="my.xslt"?>
<root>
<entity><hash>5eae206</hash><name>xiaowang</name><email>xiaowang@qq.com</email><mt>2014-01-26 17:37:58 +0800</mt><st>2016-01-26 17:37:58 +0800</st><project>branchname</project><content><![CDATA[Merge "add for cit switch issu" into 935]]></content><b>
</b></entity>
<entity><hash>e42ab38</hash><name>xiaoming</name><email>xiaoming@qq.com</email><mt>2016-01-26 17:21:37 +0800</mt><st>2016-01-26 17:21:37 +0800</st><project>branchname</project><content><![CDATA[modify version]]></content><b>
M build/core/build_id.mk

</b></entity>
<entity><hash>e319c2e</hash><name>xiaozhang</name><email>xiaozhang@qq.com</email><mt>2016-01-26 17:14:49 +0800</mt><st>2016-01-26 17:14:49 +0800</st><project>branchname</project><content><![CDATA[add for cit switch issu]]></content><b>
M modem_proc/datamodem/interface/atcop/src/dsatpar.c
M modem_proc/mmcp/mmode/qmi/src/qmi_voice.c
M aa/bb/cc_proj.h
</b></entity></root>

5个回答

︿ 0
css作为html的样式表
同样xslt可以被理解为是xml的样式表
去w3cschool上去看看吧,很快就可以入门了
︿ 0

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>
Show the entities.
</title>
</head>
<body>
<table border="1">
<caption>
<h3>
total <xsl:value-of select="count(root/entity)"/> entities.
</h3>
</caption>
<thead>
<th>
HASH
</th>
<th>
NAME
</th>
<th>
EMAIL
</th>
<th>
MT
</th>
<th>
ST
</th>
<th>
PROJECT
</th>
<th>
CONTENT
</th>
<th>
B
</th>
</thead>
<tbody>
<xsl:apply-templates select="root/entity" mode="table"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="entity" mode="table">
<tr>
<td>
<xsl:value-of select="hash"/>
</td>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="email"/>
</td>
<td>
<xsl:value-of select="mt"/>
</td>
<td>
<xsl:value-of select="st"/>
</td>
<td>
<xsl:value-of select="project"/>
</td>
<td>
<xsl:value-of select="content"/>
</td>
<td>
<xsl:value-of select="b"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>