Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: String parsing in XSL & XPath

From: "AR" <arjohn7681@-----.--->
To: 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/



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent