Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: String parsing in XSL & XPath [Thread Next] Re: String parsing in XSL & XPathTo: NULL Date: 6/2/2005 7:47:00 AM Hi,
Your are right. I want the html output what you have done.
Let me explain more what I needed. I have an xml like below ....
<html>
<a>
a 1
<b font-size="10">b 2</b>
x
<c font-size="14" font-weight="bold">c 3</c>
y
</a>
<a>
pqr
<w font-size="8">www1</w>
abc
</a>
<a>
testing 1
<r font-size="16" font-weight="bold">ALPHA</r>
done
</a>
</html>
There will be multiple <a> elements in the same level and each <a>
element will have different child nodes and text. The main thing I want
is to produce HTML from the xml. What more xsl is needed to support
multiple <a> elements? Thank you very much.
Martin Honnen wrote:
> 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:output 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
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
