I'm new to XML so any help on this topic would be greatly appreciated.
I have this XML that needs to be translated to HTML. Therefore I have decided to use XSLT to do this. The XML has a lot of formatting attributes that I need to convert into HTML tags.
For example:
<Paragraph>
<Run FontStyle="Italic" FontWeight="Bold">Bold and Italic</Run>
<Run FontWeight="Bold">Bold</Run>
</Paragraph>
There are others formatting attributes and each Run tag may have many or no formatting attributes. Therefore all Italics need to be converted to <i>, bolds to <b>, etc.
I started to use nested <xsl:choose> statements to do this but then realized it would get nasty very quickly.
<xsl:choose>
<xsl:when test="./@FontWeight = 'Bold'">
<b>
<xsl:choose>
<xsl:when test="./@FontStyle='Italic'"> <i><xsl:value-of select="."/></i>
</xsl:when>
<xsltherwise>
<xsl:value-of select="."/>
</xsltherwise>
</xsl:choose>
</b>
</xsl:when>
<xsltherwise>
<xsl:value-of select="."/>
</xsltherwise>
</xsl:choose>
There must be a better way...any ideas?
I have this XML that needs to be translated to HTML. Therefore I have decided to use XSLT to do this. The XML has a lot of formatting attributes that I need to convert into HTML tags.
For example:
<Paragraph>
<Run FontStyle="Italic" FontWeight="Bold">Bold and Italic</Run>
<Run FontWeight="Bold">Bold</Run>
</Paragraph>
There are others formatting attributes and each Run tag may have many or no formatting attributes. Therefore all Italics need to be converted to <i>, bolds to <b>, etc.
I started to use nested <xsl:choose> statements to do this but then realized it would get nasty very quickly.
<xsl:choose>
<xsl:when test="./@FontWeight = 'Bold'">
<b>
<xsl:choose>
<xsl:when test="./@FontStyle='Italic'"> <i><xsl:value-of select="."/></i>
</xsl:when>
<xsltherwise>
<xsl:value-of select="."/>
</xsltherwise>
</xsl:choose>
</b>
</xsl:when>
<xsltherwise>
<xsl:value-of select="."/>
</xsltherwise>
</xsl:choose>
There must be a better way...any ideas?