Xml 将元素关联到表XSLT中的单个节点
我对XML和XSLT非常陌生,我很难弄清楚如何将所有命名为course_num的内容放入一个单元格中,每个单元格之间用逗号隔开(每个人都有自己的单元格,其中包含课程编号) 以下是我的XML:Xml 将元素关联到表XSLT中的单个节点,xml,xslt,Xml,Xslt,我对XML和XSLT非常陌生,我很难弄清楚如何将所有命名为course_num的内容放入一个单元格中,每个单元格之间用逗号隔开(每个人都有自己的单元格,其中包含课程编号) 以下是我的XML: <?xml version="1.0" encoding="UTF-8"?> <courses> <course acad_year="2012" term_id="1" crn="108"> <course_group>COMP</course
<?xml version="1.0" encoding="UTF-8"?>
<courses>
<course acad_year="2012" term_id="1" crn="108">
<course_group>COMP</course_group>
<course_num>Ncomp</course_num>
<course_num>Hcomp</course_num>
<course_num>Scomp</course_num>
<title>XML Intro</title>
<meeting>
<meeting_begin>1820</meeting_begin>
<meeting_end>2020</meeting_end>
<location> LCOMP</location>
</meeting>
<course_head>
<person person_id="128">
<person_name>Antonio Molay</person_name>
<person_lname>Molay</person_lname>
<person_fname>Antonio</person_fname>
<person_title> College Instructor</person_title>
</person>
</course_head>
</course>
公司
Ncomp
Hcomp
嘲笑
XML简介
1820
2020
LCOMP
安东尼奥·莫利
莫莱
安东尼奥
大学讲师
这是我的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>College Courses</title>
</head>
<body>
<table>
<thead>
<tr bgcolor="yellow">
<th>Course ID</th>
<th>Year</th>
<th>Course Title</th>
<th>Teacher</th>
<th>Meeting Days</th>
<th>Time</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates />
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:variable name="dash">-</xsl:variable>
<xsl:template match="course">
<tr>
<td>
<xsl:value-of select="course_num" />
</td>
<td>
<xsl:value-of select="@acad_year" />
</td>
<td>
<xsl:value-of select="course_group" />
</td>
<td>
<xsl:value-of select="course_head/person/person_name" />
</td>
<td>
<xsl:value-of select="concat(meeting/meeting_begin, $dash, meeting/meeting_end)" />
</td>
<td>
<xsl:value-of select="meeting/location" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
大学课程
课程ID
年
课程名称
教师
会议日
时间
地方
-
我知道每个循环都需要一个循环,但不确定如何将其放入TD。。我尝试了许多不同于前面问题的解决方案,但都不起作用。任何帮助都将不胜感激,请记住我是个笨蛋,所以请具体说明。谢谢
如何将所有名为course_num的内容放入一个单元格中
每个都用逗号分隔
更改:
<td>
<xsl:value-of select="course_num" />
</td>
致:
,
哇,这很简单。它工作得很好。我不知道为什么我对这件事如此着迷。非常感谢!!!!!!!
<td>
<xsl:for-each select="course_num">
<xsl:value-of select="." />
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</td>