Reputation: 43
I'm new to XSLT and a bit confused about formating lists. Basicly I need my XML structure, there's a part of it:
<slideshow>
<slide id="A1">
<title>XML techniques</title>
<paragraph> Slideshow prepresents different kind of <bold>XML</bold> techniques </paragraph>
<paragraph> Most common XML Techniques are </paragraph>
<numberedlist>
<item> Basic XML, DTD (version 1.0) </item>
<item> XHTML </item>
<itemizedlist>
<item> XHTML 1.0 </item>
<item> XHTML basic </item>
<numberedlist>
<item> for mobile phones </item>
<item> basic set for all XHTML documents</item>
</numberedlist>
</itemizedlist>
<item> XML namespace </item>
<item> XSL </item>
<itemizedlist>
<item> XSLT - template based programming language</item>
<item> XSL-FO - formating output like CSS </item>
</itemizedlist>
<item> Programming API (like SAX and DOM) </item>
<item> XML Schemas </item>
</numberedlist>
</slide>
..
</slideshow>
To look like this:
I wanted to do this as simple as possible, so I was just using templates and no complicated XPath masks, but seems like there's no simply way.. Could someone help? Thank you!
Upvotes: 0
Views: 1178
Reputation: 116982
Actually, this is trivial in XSLT, due to it's recursive processing model.
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="numberedlist">
<ol>
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="itemizedlist">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:value-of select="." />
</li>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Result
<ol>
<li> Basic XML, DTD (version 1.0) </li>
<li> XHTML </li>
<ul>
<li> XHTML 1.0 </li>
<li> XHTML basic </li>
<ol>
<li> for mobile phones </li>
<li> basic set for all XHTML documents</li>
</ol>
</ul>
<li> XML namespace </li>
<li> XSL </li>
<ul>
<li> XSLT - template based programming language</li>
<li> XSL-FO - formating output like CSS </li>
</ul>
<li> Programming API (like SAX and DOM) </li>
<li> XML Schemas </li>
</ol>
rendered:
Upvotes: 2