Reputation: 39
I'm working on an XSLT script to output an HTML table containing data from an XML file but my resulting document is only giving me the first set when I need each set.
This is my 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>
This is my 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>
This is the output I'm getting:
<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>
This is what I'm trying to get:
<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>
Where is my script off? Thanks in advance for any help!
Upvotes: 0
Views: 81
Reputation: 116959
Try it this way:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/map">
<html>
<body>
<h2></h2>
<table border="1">
<xsl:for-each select="topicref">
<tr>
<td><xsl:value-of select="@href"/></td>
<td><xsl:value-of select="topicsubject/@keyref"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
See the Repetition section in XSLT specification.
Upvotes: 2
Reputation: 167436
I think you want something along the lines of
<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>
Upvotes: 2