XSL Transform for Multiple Child Elements



Team


I am an absolute newbie to XSLT. I am trying my hand at some automation. I want to be able to create the following output using the below XML code of text:


My XSLT



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0">
<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>KT/Definitions List</title>
</head>
<body>
<h2>KT/Definitions List</h2>
<table border="1">
<thead>
<tr>
<th>KT</th>
<th>Definition</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="cl:doc//cl:key-term-entry"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="cl:key-term-entry">
<tr>
<td><xsl:value-of select="cl:key-term"/></td>
<td><xsl:value-of select="cl:key-term-def"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>


My Part XML Input



<cl:key-term-entry identifier="JMTMRA930472614">
<cl:key-term identifier="DXYKHJ261631149">availability sampling</cl:key-term>
<cl:key-term-def identifier="BKPHVJ904214958">A sampling method that selects elements simply because of their ready availability and convenience. Frequently used in social work because it is usually less expensive than other methods and because other methods may not be feasible for a particular type of study or population. See also
<cl:style styles="italic">accidental sampling</cl:style>,
<cl:style styles="italic">convenience sampling</cl:style>, and
<cl:xref link-target="KRJPJV275444397" ordinal="11" pre-text="Chapter "/>.
</cl:key-term-def>
</cl:key-term-entry>


MY XSLT Output



<tr>
<td>availability sampling</td>
<td>A sampling method that selects elements simply because of their ready availability and convenience. Frequently used in social work because it is usually less expensive than other methods and because other methods may not be feasible for a particular type of study or population. See also accidental sampling, convenience sampling, and .</td>
</tr>


MY Desired XSLT Output



<tr>
<td>availability sampling</td>
<td>A sampling method that selects elements simply because of their ready availability and convenience. Frequently used in social work because it is usually less expensive than other methods and because other methods may not be feasible for a particular type of study or population. See also <i>accidental sampling</i>, <i>convenience sampling</i>, and <a href="chapter11.html">Chapter 11</a>.</td>
</tr>


As you can see from my output (not my desired output), I am unable to understand how to add the <i> tags and <a> tag here. In fact, the self-closing <cl:xef> tag (whose attribute values have to be transformed as <a> tag) is empty in my output. Any help here will advance my knowledge of XSLT.


Thanks, Prem


No comments:

Post a Comment