SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XSLT and (X)HTML

    Anybody know what XML/XSLT parsers do when they encounter XHTML or HTML in a document they are parsing? Do they just leave it alone (and note it as the contents of the parent tag they found it in; this is the desired result)?

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's XHTML it looks like any other well formed XML file to the parser. He doesn't know how to handle it until you tell him (via the XSL-Stylesheet).

    If it's HTML (which may not be well-formed XML like <br> instead of <br/>) the parser will spit out an error about the document being not well-formed. You can avoid this either by using XHTML (which *is* well-formed XML) or you place the 'bad' HTML into <![CDATA[...]]> and output it withoud output-escaping switched on.
    include_once('./sig.inc.php');

  3. #3
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, maybe I'm not being clear enough. In this scenario, none of the XHTML/HTML is being defined in the XSL, as I would like the parser to treat it as it does the contents of any tag(and leave it intact.) Maybe it would help if I explained the purpose: I am considering using XML and XSLT for the content format of a CMS. Since I'll need some articles to include HTML or XHTML that will need to be escaped and shown on screen, I was wondering if the parser would let it through.

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried it and he dropped the tags.

    If you put the HTML into <![CDATA[]]> it can be passed through.
    include_once('./sig.inc.php');

  5. #5
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right on. Thanks for your help

  6. #6
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going about it wrong. Your CMS shouldn't really allow you to use XHTML directly, else you might as well just use XHTML for the whole lot. What you should do is define a limited set of tags that can be used to markup the data, e.g. define <subheading> etc. in your XSLT then apply say bold formatting and size 3 font to it from the XSLT. XML shouldn't store presentation, only data.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  7. #7
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your concern, but it's there so it can be printed to screen. Luckily, CDATA sections do entity conversions automatically, so this is the best option for me.


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
  •