xslt - 使用 XSLT 如何让我的输出重复而不是只返回第一个实例?
问题描述
我正在编写一个 XSLT 脚本来输出一个包含来自 XML 文件的数据的 HTML 表,但我生成的文档只在我需要每组时才给我第一组。
这是我的 XML:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE map PUBLIC "-//KPE//DTD DITA KPE Map//EN" "kpe-map.dtd" []>
<map>
<title><ph conref="../../titles/sec_s63_title_l1.dita#sec_s63_title_l1/topic_title"/></title>
<topicref href="../questions/sec_question_00260_1.dita">
<topicsubject keyref="sec_s63_los_1"/>
</topicref>
<topicref href="../questions/sec_question_00260_2.dita">
<topicsubject keyref="sec_s63_los_1"/>
</topicref>
<topicref href="../questions/sec_question_00260_3.dita">
<topicsubject keyref="sec_s63_los_1"/>
</topicref>
</map>
这是我的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<html>
<body>
<h2></h2>
<table border="1">
<tr>
<td><xsl:value-of select="//topicref/@href"/></td>
<td><xsl:value-of select="//topicref/topicsubject/@keyref"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这是我得到的输出:
<html>
<body>
<h2></h2>
<table border="1">
<tr>
<td>../questions/sec_question_00260_1.dita</td>
<td>sec_s63_los_1</td>
</tr>
</table>
</body>
</html>
这就是我想要得到的:
<html>
<body>
<h2></h2>
<table border="1">
<tr>
<td>../questions/sec_question_00260_1.dita</td>
<td>sec_s63_los_1</td>
</tr>
<tr>
<td>../questions/sec_question_00260_2.dita</td>
<td>sec_s63_los_1</td>
</tr>
<tr>
<td>../questions/sec_question_00260_3.dita</td>
<td>sec_s63_los_1</td>
</tr>
</table>
</body>
</html>
我的脚本在哪里关闭?提前感谢您的帮助!
解决方案
我想你想要一些类似的东西
<xsl:template match="/">
<html>
<body>
<h2></h2>
<table border="1">
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="topicref">
<tr>
<td><xsl:value-of select="@href"/></td>
<td><xsl:value-of select="topicsubject/@keyref"/></td>
</tr>
</xsl:template>
推荐阅读
- excel - 我实际上希望在使用 VBA 打开另一个 Excel 文件时更新 Excel 链接,但是,我只能找到如何抑制问题
- bokeh - 散景线图显示没有 y 轴值
- python-asyncio - 必须 __aenter__ 返回一个可等待的吗?
- php - 在类和带有数组的函数中使用变量
- python - 查找字符串中的最后一个空格(对你来说很简单,而不是我)
- django - 如何在 Django 中处理多种动态用户类型?
- github - Git hub switch 上传仓库
- javascript - 这是将一个数组分成两个数组的最有效方法吗?
- jakarta-mail - JavaMail SMTP 因 iCloud 失败
- firebase - 无限循环 - React Native useState useEffect