SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying embedded html from an xml file through an xsl style sheet

    Hi chaps

    I've got an XML file, within that file i've embedded html code using the
    <![CDATA[ ]]>
    tag

    I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying any html from the xml file as text, ie its displaying as text <br/> and <b> etc

    How can i tell my xml file to display the html tags as html and not display them as text?

    Many thanks

  2. #2
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    solution found!

    <xsl:value-of disable-output-escaping="yes"........

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    atlanta
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink embedding html ttags in xml

    Hi Guys,

    I have a scenario:

    XML File:

    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/xsl" href="mystyle.xsl" ?>
    <reportpage>
    <name>Bid Administration Report Summary</name>
    <htmldata> <b>abcd></b> should appear bold. any html tags can appear here.</htmldata>
    </reportpage>

    I wanted to know if anything in <htmldata> tag, can be made to be processed as HTML. Meaning 'abcd' should appear bold in the browser. Right now, it is ignoring the bold tag. Below is the xsl i am using. Please let me know if this is possible guys.

    My XSL file:

    <?xml version="1.0"?>
    <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="reportpage">
    <html>
    <head>
    <title><xsl:value-of select="name" /></title>
    </head>
    <body>
    <h1 align="center"><xsl:value-of select="name" /></h1>

    <xsl:value-of select="htmldata" disable-output-escaping="yes" />
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>


    Thanks in advance,

    Arun

  4. #4
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The better solution is to encapsulate the data like so:
    Code:
     <?xml version="1.0" ?>
    <?xml-stylesheet type="text/xsl" href="mystyle.xsl" ?>
    <reportpage>
    <name>Bid Administration Report Summary</name>
    <htmldata> <![CDATA[ <b>abcd></b> should appear bold. any html tags can appear here. ]]></htmldata>
    </reportpage>
    As, technically speaking, you are not adding a <b> element to the <htmldata> block, but rather adding data - so a CDATA section is preferred.

    ... but if you really wanted to keep it how you have it, just replace
    Code:
     <xsl:value-of select="htmldata" disable-output-escaping="yes" />
    with
    Code:
     <xsl:copy-of select="htmldata" />
    Studio Rockstar's Blog - A journey to quitting the dayjob.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •