Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: String parsing in XSL & XPath

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/2/2005 1:15:00 PM

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