AR wrote:
I have an xml like this:
<a>
a 1
<b font-size="10">b 2</b>
x
<c font-size="14" font-weight="bold">c 3</c>
y
</a>
The output will be like below with the corresponding font size and
weight in HTML:
a 1 b 2 x c 3 y
That does not look like HTML at all to me but perhaps the following
How can I do it using XSL and XPath?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl
utput method="html" />
<xsl:template match="b | c">
<span>
<xsl:choose>
<xsl:when test="@font-size and @font-weight">
<xsl:attribute name="style">
<xsl:text>font-size : </xsl:text>
<xsl:value-of select="@font-size" />
<xsl:text>px; font-weight : </xsl:text>
<xsl:value-of select="@font-weight" />
</xsl:attribute>
</xsl:when>
<xsl:when test="@font-size">
<xsl:attribute name="style">
<xsl:text>font-size : </xsl:text>
<xsl:value-of select="@font-size" />
<xsl:text>px</xsl:text>
</xsl:attribute>
</xsl:when>
<xsl:when test="@font-weight">
<xsl:attribute name="style">
<xsl:text>font-weight : </xsl:text>
<xsl:value-of select="@font-weight" />
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:apply-templates />
</span>
</xsl:template>
</xsl:stylesheet>
is what you are looking for, result of the transformation is
a 1
<span style="font-size : 10px">b 2</span>
x
<span style="font-size : 14px; font-weight : bold">c 3</span>
y