Looking to transform an XML file to a valid DTD topic. To do this I need to insert a body element as shown.
<topic>
<title>My Title</title>
==><body>
<para>Intro text goes here.</para>
<section/>
<section/>
==></body>
</topic>
Looking to transform an XML file to a valid DTD topic. To do this I need to insert a body element as shown.
<topic>
<title>My Title</title>
==><body>
<para>Intro text goes here.</para>
<section/>
<section/>
==></body>
</topic>
Copyright © 2021 Jogjafile Inc.
If you need to add a
bodyelement as a child oftopic, add a template that matchestopicand add the element there.The only slightly tricky part is that you want the
titleoutside ofbody, so you'll have to separate that from the rest of the children.Here's an XSLT 3.0 example. (I also added an
idattribute totopicand changedparatopso it would be valid.)If you can't use XSLT 3.0, here's a 1.0 version (without
xsl:modeandexcept)...Fiddle: http://xsltfiddle.liberty-development.net/3Nzb5iZ