DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Re: How can I include html in my xml file ? with copy-of...

Hybrid View

  1. #1
    jerome Guest

    Re: How can I include html in my xml file ? with copy-of...


    Finally I found a solution...

    if the html text is wel formatted, why not just copy all the element as is
    by the <xsl:copy-of select="."/> method...


    "djer" <jerome.albessard@wtcm.be> wrote:
    >
    >hello,
    >
    >second basic question:
    >I have a xml file with the element description who's contains html formatted
    >text:
    >
    ><description>
    > <H1>some html formatted text</H1>
    ></description>
    >
    >and I would like retrieve this with xsl by
    >
    ><xsl:template match="description">
    > <value-of select=".">
    ></xsl:template>
    >
    >and have as result an html file with
    >
    > <H1>some html formatted text</H1>
    >
    >it's possible ?
    >
    >thankxx
    >
    >djer



  2. #2
    Russell Jones Guest

    Re: How can I include html in my xml file ? with copy-of...

    Here's an example.

    WARNING!
    I'm using the newer XSLT namespace, not the XSL namespace that works with
    the XML parser shipped with IE. For the example to work, you'll need to
    download and install a more recent version of the msxml.dll parser from
    MSDN. Be sure to run the xmlinst.exe file to install the parser in "replace"
    mode.
    If you don't want or are unable to upgrade your parser version, here's the
    relevant information you'll need.
    1. Place the HTML inside a CDATA section. That prevents the XML parser from
    parsing the contents and raising errors if the HTML isn't perfectly
    formatted for XML.
    2. Include the disable-output-escaping="yes" attribute when you retrieve the
    contents of the CDATA section. That prevents the parser from substituting
    entities for the invalid XML characters (such as the angle brackets, quotes,
    etc.)

    Place this XML file: called "htmltest.xml"

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="htmltest.xsl"?>
    <root>
    <description>
    <![CDATA[
    <HTML><HEAD>
    <TITLE>Test file</TITLE>
    </HEAD>
    <BODY><h1>My Heading 1</h1>
    </BODY></HTML>]]>
    </description>
    </root>


    and this XSL file, called "htmltest.xsl", in the same directory.

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xslutput method="html" omit-xml-declaration="yes"/>
    <xsl:template match="/">
    <xsl:apply-templates select="root/description"/>
    </xsl:template>
    <xsl:template match="description">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:template>
    </xsl:stylesheet>

    Now browse to the htmltest.xml file with IE5. The browser displays the HTML
    document stored in the CDATA section.

    Russell Jones
    Sr. Web Development Editor
    DevX.com


    "jerome" <jerome.albessard@wtcm.be> wrote in message
    news:3a7aa073$1@news.devx.com...
    >
    > Finally I found a solution...
    >
    > if the html text is wel formatted, why not just copy all the element as is
    > by the <xsl:copy-of select="."/> method...
    >
    >
    > "djer" <jerome.albessard@wtcm.be> wrote:
    > >
    > >hello,
    > >
    > >second basic question:
    > >I have a xml file with the element description who's contains html

    formatted
    > >text:
    > >
    > ><description>
    > > <H1>some html formatted text</H1>
    > ></description>
    > >
    > >and I would like retrieve this with xsl by
    > >
    > ><xsl:template match="description">
    > > <value-of select=".">
    > ></xsl:template>
    > >
    > >and have as result an html file with
    > >
    > > <H1>some html formatted text</H1>
    > >
    > >it's possible ?
    > >
    > >thankxx
    > >
    > >djer

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center