Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to display HTML inside XML file as real HTML using XLST

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 1/28/2008 1:05:00 PM

guoqi zheng wrote:

> I have below XML file, inside the body tag, those are real html code, when I 
> display them using XLST, I lost all the attribute defined inside the HTML 
> code. For example <b> tag did not display text in bold format any more. How 
> can I display them as real HTML? 
> 
> ----------------------------------------------------------
> <Content xmlns="uuid:F5940E5C-0D24-4460-821C-8ACA4DFD6FFA">
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This default namespace declaration applies to all descendants too so the 
elements like p or b or br are in that namespace too while for HTML they 
need to be in no namespace, for XHTML they need to be in the XHTML 
namespace http://www.w3.org/1999/xhtml.
>   <Title>Equal Project</Title> 
>   <Intro>no intro here.</Intro> 
> <Body>
> <p>
> this is some text here <b>this is bold</b>
> <br/>
> <br/>
> <a href="something.asp">test link</a>
> </p>
> </Body>
> </Content>

To fix that strip the namespace of those elements e.g.
   <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"
     xmlns:df="uuid:F5940E5C-0D24-4460-821C-8ACA4DFD6FFA"
     exclude-result-prefixes="df">

     <xsl:template match="df:p | df:b | df:a | df:br">
       <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@* | node()"/>
       </xsl:element>
     </xsl:template>

     <xsl:template match="/">
       <html>
         <head>
           <title><xsl:value-of select="df:Content/df:Title"/></title>
         </head>
         <body>
           <xsl:apply-templates select="df:Content/df:Body/*"/>
         </body>
       </html>
     </xsl:template>

     <xsl:template match="@*">
       <xsl:copy/>
     </xsl:template>
   </xsl:stylesheet>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Digg
delicious
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