Embed HTML in XML

Discussion in 'XML' started by csgraham74, Jun 13, 2007.

  1. csgraham74

    csgraham74 Guest

    Ok - i was wondering if someone could help me.

    im basically trying to embed an html string in piece of XML. i
    created an xsl and added the CDATA into the xml around the html i wish
    to render. In my calling page i create an XML data island (excuse the
    terminology as im new to this stuff) to pull in the xml fields and
    to hopefully render the html as xml (see Details node ) .
    Unfortunately this doesnt work and it just displays as a string
    output.

    If anyone could give me some assistnace on this it would be a great
    help, if im totally barking up the wrong tree please tell me.

    the only thing i must say is that i need to creata HTML inside the XML
    node as im using a third party control to create this.

    My current output is a table with all fields pulling in corrctly
    except the details node.

    Any help on this appreciated.

    XML DATA ISLAND
    <xml id="cdcat" src="/experience/includes/test.xml"></xml>
    <table border="1" datasrc="#cdcat">

    <tr>
    <td><span datafld="Title"></span></td>
    <td><span datafld="Date"></span></td>
    <td><span datafld="Info"></span></td>
    <td><span datafld="Details"></span></td>
    </tr>

    XML

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="style.xsl"?>
    <Data>
    <Title>Test 1</Title>
    <Date>20th June 2007</Date>
    <Info>ghsdgfhsdgfh fdsfhjsdfhjh fsdfjhsdfjhhfjh fhsjdfhjshdfjhj
    sjdfhjsdhfjhj fhjshdfsdj jdfhjhsdfhhfhsf</Info>
    <Details><!
    [CDATA[<P>xxxxx<BR>hfsjdhjsdfh<BR><BR>sdfjksjdfkksfj<BR><BR>sdfjmsdfsdfj<BR><BR><BR>sdfjskjdfkjskjfksj<BR></
    P>]]></Details>
    </Data>

    XSL

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="Details">
    <xsl:value-of select="//Data/Details" disable-output-escaping="yes"/
    >

    </xsl:template>
    </xsl:stylesheet>
     
    csgraham74, Jun 13, 2007
    #1
    1. Advertising

  2. csgraham74

    Peter Flynn Guest

    csgraham74 wrote:
    > Ok - i was wondering if someone could help me.
    >
    > im basically trying to embed an html string in piece of XML. i
    > created an xsl and added the CDATA into the xml around the html i wish
    > to render.


    Don't. Leave it as normal markup and add suitable templates to your XSL
    to handle it.

    See the FAQ: http://xml.silmaril.ie/authors/html/

    XML

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="style.xsl"?>
    <Data>
    <Title>Test 1</Title>
    <Date>20th June 2007</Date>
    <Info>ghsdgfhsdgfh fdsfhjsdfhjh fsdfjhsdfjhhfjh fhsjdfhjshdfjhj
    sjdfhjsdhfjhj fhjshdfsdj jdfhjhsdfhhfhsf</Info>
    <Details>
    <P>xxxxx<BR/>hfsjdhjsdfh<BR/>
    <BR/>sdfjksjdfkksfj<BR/>
    <BR/>sdfjmsdfsdfj<BR/>
    <BR/><BR/>sdfjskjdfkjskjfksj<BR/></P>
    </Details>
    </Data>

    then

    XSL

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="Details">
    <xsl:copy-of select="."/>
    </xsl:template>

    </xsl:stylesheet>

    ///Peter
     
    Peter Flynn, Jun 14, 2007
    #2
    1. Advertising

  3. csgraham74

    csgraham74 Guest

    thanks peter - i really appreciate the help

    i have created the following template and it displays the xml
    correctly when i open my .xml document in my browser.

    However when i try to embed this in html it still displays as before -
    why is this happening ?? can i apply my style from with my HTML
    document ????

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="Details">
    <p>
    <xsl:apply-templates select="Details"/>
    </p>
    </xsl:template>
    <xsl:template match="Details">
    <xsl:value-of select="//Data/Details" disable-output-escaping="yes"/
    >

    </xsl:template>
    </xsl:stylesheet>

    it
     
    csgraham74, Jun 14, 2007
    #3
  4. csgraham74

    Andy Dingley Guest

    On 13 Jun, 18:29, csgraham74 <> wrote:

    > im basically trying to embed an html string in piece of XML.


    Looks more like you're having trouble putting XML into HTML.

    > i create an XML data island


    An obsolete and non standards-based M$oft technique that's best
    avoided. Look at the AJAX route, not "data islands".

    If embedding HTML inside your XML is also a problem, then look at how
    RSS does it (mainly by encoding "<" as "&lt;" etc.). There's a
    famously good web page out there on "diveintomark" called "The myth of
    RSS version compatibility".
     
    Andy Dingley, Jun 14, 2007
    #4
  5. Peter Flynn wrote:
    > csgraham74 wrote:
    >> Ok - i was wondering if someone could help me.
    >>
    >> im basically trying to embed an html string in piece of XML. i
    >> created an xsl and added the CDATA into the xml around the html i wish
    >> to render.

    >
    > Don't. Leave it as normal markup and add suitable templates to your XSL
    > to handle it.


    This was exactly what I was looking for but had not yet taken the time
    to create a clean posting. Thank you.

    I needed to add the namespace for XHTML to get it to work for me. Here
    is a fragment from one my XML files where the <pretext> element may
    include XHTML content.

    <equipment xmlns="http://emle.sourceforge.net/emle020100"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <id>3</id>
    <title>Solid Rectangle Fraction</title>
    <value>
    <pretext>
    <xhtml:em>Unsegmented</xhtml:em> rectangle selectable by the
    enclosed buttons.
    </pretext>

    Here is a slightly edited fragment from the XSLT file that passes the
    XHTML content within <pretext> to the output file:

    <xsl:template match="emle:value">
    <div class="emleValue">
    <div class="emlePreText"><xsl:copy-of select="emle:pretext" /></div>
    <xsl:apply-templates
    select="emle:control|emle:constant|emle:graphic" />
    <div class="emlePostText">
    <xsl:copy-of select="emle:posttext" /></div>
    </div>
    </xsl:template>

    The complete files are here:

    http://emle.sourceforge.net/emle020100/lab/emle_lab_011.xml
    http://emle.sourceforge.net/emle020100/emle_lab_011.xsl
    http://emle.sourceforge.net/emle020100/equipment/emle_equipment_3.xml

    I am using "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4)
    Gecko/20070515 Firefox/2.0.0.4" which may be needed for the pages to
    display.

    --
    C.W.Holeman II | -5 http://JulianLocals.com/cwhii
    To only a fraction of the human race does God give the privilege of
    earning one's bread doing what one would have gladly pursued free, for
    passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
     
    C.W.Holeman II, Jun 14, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helixpoint

    embed an image in an HTML email.

    Helixpoint, Jul 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    551
    J. Ptak
    Jul 16, 2003
  2. Jerry III
    Replies:
    0
    Views:
    2,859
    Jerry III
    Oct 15, 2003
  3. Olav Tollefsen

    How to embed dynamic generated image into HTML?

    Olav Tollefsen, Mar 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,958
    Olav Tollefsen
    Mar 1, 2004
  4. Failure
    Replies:
    1
    Views:
    1,140
    Failure
    Sep 7, 2003
  5. jalexa9898
    Replies:
    8
    Views:
    1,070
    Peter Flynn
    Sep 3, 2006
Loading...

Share This Page