[英]How to choose a attributes from XML using the XSLT?
<students>
<student student-name="Leo">
<program> BIT </program>
<study-model> on-campus </study-model>
</student>
<student student-name="Dan">
<program> MIT </program>
<study-model> off-campus </study-model>
</student>
</students>
谁能帮我 ? 我仍然是XML-XSLT的新手。。我正在尝试为上述XML数据开发XSTL。
就像我只想选择学生姓名Dan一样,包括XML和XML输出的程序和学习模型。
我应该使用什么代码从XML中选择属性?
输出示例如下:
与数据略有不同(使用学生姓名而不是学生编号等)
您可以执行以下操作:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes" />
<xsl:template match="students">
<table>
<xsl:apply-templates select="student" />
</table>
</xsl:template>
<xsl:template match="student">
<tr>
<td>
Student Name: <xsl:value-of select="@student-name" />
</td>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="*">
<td>
<xsl:value-of select="name(.)" />: <xsl:value-of select="." />
</td>
</xsl:template>
</xsl:stylesheet>
这将输出:
<table>
<tr>
<td>
Student Name: Leo</td>
<td>program: BIT </td>
<td>study-model: on-campus </td>
</tr>
<tr>
<td>
Student Name: Dan</td>
<td>program: MIT </td>
<td>study-model: off-campus </td>
</tr>
</table>
您可以通过在xsl中将类添加到td中,然后添加css来设置此表的样式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.