Hello, we receive an XML file from Oracle. In this file, unfortunately one of the hierarchies is created in a not exactly standard format, although it is still valid. Here is an example:
<topics>
<topic>Topic 1
<sub_topics>
<sub_topic>Sub topic 1_1</sub_topic>
<sub_topic>Sub topic 1_2 </sub_topic>
</sub_topics>
</topic>
<topic>Topic 2
<sub_topics>
<sub_topic>Sub topic 2_1</sub_topic>
<sub_topic>Sub topic 2_2 </sub_topic>
</sub_topics>
</topic>
<topics>
As you can see "Topic 1" and "Topic 2" are not rapped into their own tags, for instance <hdr>Topic 1</hdr>. I would consider this way more standard
Currently, if I apply the following XSLT snippet to this section:
p><i>Topics: </i></p>
<xsl:for-each select="topics">
<ul>
<xsl:for-each select="topic">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>
The HTML result is:
Topics:
- Topic 1 Topic 1_1 Topic 1_2
- Topic 2 Topic 2_1 Topic 2_2
If I wrap the topics into a set of additional tags, like that
<topics>
<topic><hdr>Topic 1</hdr>
<sub_topics>
<sub_topic>Sub topic 1_1</sub_topic>
<sub_topic>Sub topic 1_2 </sub_topic>
</sub_topics>
</topic>
<topic><hdr>Topic 2</hdr>
<sub_topics>
<sub_topic>Sub topic 2_1</sub_topic>
<sub_topic>Sub topic 2_2 </sub_topic>
</sub_topics>
</topic>
<topics>
And modify my XSLT like that:
<p><i>Topics: </i></p>
<xsl:for-each select="topics/topic">
<xsl:for-each select="hdr">
<p><xsl:value-of select="." /></p>
</xsl:for-each>
<ul>
<xsl:for-each select="sub_topics/sub_topic">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:for-each>
The result is fine:
Topics:
Topic 1
Topic 2
Question: I would prefer to change the XSL to handle this exception rather than writing a parser in PLSQL and adding the new tags, which I can do for sure. I would appreciate if one of XSLT aces show me the way how to modify my XSL file.
Thanks in advance
<topics>
<topic>Topic 1
<sub_topics>
<sub_topic>Sub topic 1_1</sub_topic>
<sub_topic>Sub topic 1_2 </sub_topic>
</sub_topics>
</topic>
<topic>Topic 2
<sub_topics>
<sub_topic>Sub topic 2_1</sub_topic>
<sub_topic>Sub topic 2_2 </sub_topic>
</sub_topics>
</topic>
<topics>