How to create custom XHTML tag?

Discussion in 'HTML' started by janecki@gmail.com, May 12, 2006.

  1. Guest

    Hello!
    I want to create a custom XHTML tag.

    1) I have something like this:
    <table>
    <tr> <td> TITLE </td> </tr>
    <tr> <td> MESSAGE </td></tr>
    </table>

    2) After creating new tag:
    <window title="TITLE">MESSAGE</window>

    Please tell me how to create a custom tags in XHTML.(example)

    Thanks!
     
    , May 12, 2006
    #1
    1. Advertising

  2. ironcorona Guest

    wrote:
    > Hello!
    > I want to create a custom XHTML tag.
    >
    > 1) I have something like this:
    > <table>
    > <tr> <td> TITLE </td> </tr>
    > <tr> <td> MESSAGE </td></tr>
    > </table>
    >
    > 2) After creating new tag:
    > <window title="TITLE">MESSAGE</window>
    >
    > Please tell me how to create a custom tags in XHTML.(example)


    Why do you want to create a custom tag? What will your new tag do that
    you can't do with an XHTML tag and CSS?

    If you really want to do this you have to create a custom DTD. I'd
    strongly advise against doing this.


    --
    Brian O'Connor (ironcorona)
     
    ironcorona, May 12, 2006
    #2
    1. Advertising

  3. Guest

    I'd like to make my own "XHTML tags library".
    I don't want to waste time to write all this tds and trs (see example).
    I'd like to encapsulate that in one tag.
     
    , May 12, 2006
    #3
  4. ironcorona Guest

    wrote:
    > I'd like to make my own "XHTML tags library".
    > I don't want to waste time to write all this tds and trs (see example).
    > I'd like to encapsulate that in one tag.


    ....I'm just not sure what to say.

    Do you know CSS? Have you tried *not* using a table? Or generating the
    table some other way?

    There's a reason there's a standard for XHTML. It's so everyone's
    singing from the same song book.

    --
    Brian O'Connor (ironcorona)
     
    ironcorona, May 12, 2006
    #4
  5. wrote:
    > I want to create a custom XHTML tag.


    You can't. XHTML is a defined set of elements. You can create your own XML
    language and (with namespaces) mix it with XHTML, but browser support is
    weak, and you won't get any semantics from the extra elements recognised by
    user agents.

    > 1) I have something like this:
    > <table>
    > <tr> <td> TITLE </td> </tr>
    > <tr> <td> MESSAGE </td></tr>
    > </table>


    A one by two table? This shouts "Abusing tables for layout". You should
    probably read http://allmyfaqs.net/faq.pl?Tableless_layouts

    > 2) After creating new tag:
    > <window title="TITLE">MESSAGE</window>


    Well, you could create your own XML format to store your data in the form
    you like, and then use XSLT to transform it into (X)HTML (preferably on the
    server).

    I've done very little with XSLT, but have started reading
    http://www.oreilly.com/catalog/learnxslt/index.html - and it seems decent
    enough.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, May 12, 2006
    #5
  6. David Segall Guest

    wrote:

    >Hello!
    >I want to create a custom XHTML tag.

    You can't. At least you can, but no browser would understand it.

    If you want to write your own tags you need to process them on the
    server to turn them into [X]HTML that all browsers understand. For
    example, Servlets (on the server) and JavaServer Pages on your web
    site allow you define your own tag library.
     
    David Segall, May 13, 2006
    #6
  7. Toby Inkster Guest

    janecki wrote:

    > 2) After creating new tag:
    > <window title="TITLE">MESSAGE</window>


    XHTML doesn't allow you to create new tags at will. The X (extensibility)
    part of XHTML comes from the fact that it's easy the for standards setters
    (i.e. browser makers, etc) to create extended versions of XHTML for
    particular purposes -- for example, the XHTML+Voice standard for
    interactive voice pages (currently only supported by Opera 7.5+ on Windows
    2000/XP); and XHTML+MathML+SVG. The X part of XHTML doesn't really help
    ordinary folk like you and me to create new elements like the above.

    It looks to me like more suitable markup for your example might be:

    <div class="window">
    <h2>Title</h2>
    <div>
    Message.
    </div>
    </div>

    you can then use CSS to style that how you like. For example:

    .window { border: 2px solid #060; margin: 1em; padding: 0; }
    .window H2 { margin: 0; padding: 4px; background: #060; color: white; }
    .window DIV { margin: 0; padding: 4px; color: #060; background: white; }

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, May 13, 2006
    #7
  8. On Sat, 13 May 2006, Toby Inkster wrote:

    > The X part of XHTML doesn't really help
    > ordinary folk like you and me to create new elements like the above.


    Strictly speaking, what you say is true. And I wouldn't actually
    recommend doing what I'm about to discuss, for real-life web pages,
    but it can be an interesting experiment.

    Let's assume for the sake of discussion that Ruby Annotation hadn't
    yet been specified by W3C. And indeed the majority of browsers behave
    as if it hadn't been. Now take a look at
    http://www.w3.org/People/mimasa/test/schemas/NOTE-ruby-implementation#stylesheets
    which presents some sample CSS stylesheets for it.

    I tried this out, at
    http://ppewww.ph.gla.ac.uk/~flavell/www/umusalu.html , using
    HTML-flavoured markup (but XHTML can be just as effective), and it
    sort-of works in a few browsers, even though the browsers have no
    knowledge or understanding of the markup itself, and are doing no more
    than applying the supplied CSS rules to what, to them, are undefined
    tags. I didn't even bother to supply a custom DOCTYPE to include the
    syntax for these elements.

    But I must repeat that I wouldn't recommend doing that for a real
    production web page.

    regards
     
    Alan J. Flavell, May 13, 2006
    #8
  9. Guest

    I've done almost it. Check this out in web browser:

    file: index.xml

    <?xml version="1.0" encoding="ISO-8859-2"?>
    <?xml-stylesheet type="text/xsl" href="tereska.xsl"?>

    <doc>
    <window title="Cool!">working working working </window><br/>
    <window title="Cool!">working working working </window><br/>
    <window title="Cool!">working working working </window><br/>
    </doc>


    file: tereska.xsl

    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="doc">
    <html><head><title></title>

    <style>
    ..title { font-size: 16px;
    color: white;
    font-family: "Trebuchet MS";
    font-weight: bold;
    }
    ..message { font-size: 12px;
    color: black;
    font-family: "Trebuchet MS";
    font-weight: normal;
    }

    </style>
    </head>
    <body><xsl:apply-templates/></body></html>
    </xsl:template>


    <xsl:template match="window">
    <table cellspacing="0" border="0" width="150" style="border: 1px
    solid darkblue;">
    <tr><td bgcolor="darkblue" align="center"
    class="title"><xsl:value-of select="@title"/></td></tr>
    <tr><td class="message"><xsl:apply-templates/></td> </tr>
    </table>
    </xsl:template>


    <xsl:template match="br">
    <br/>
    </xsl:template>


    </xsl:stylesheet>


    Now i must figureout how to embed this in XHTML document.
    It is possible with namespaces but I don't know how to do this right
    now.
     
    , May 14, 2006
    #9
  10. ironcorona Guest

    wrote:
    > I've done almost it. Check this out in web browser:
    >
    > file: index.xml
    >
    > <?xml version="1.0" encoding="ISO-8859-2"?>
    > <?xml-stylesheet type="text/xsl" href="tereska.xsl"?>


    [snip]

    It's not working for me. You might wish to specify an absolute URI in
    the xml-stylesheet deceleration.



    --
    Brian O'Connor (ironcorona)
     
    ironcorona, May 14, 2006
    #10
  11. ironcorona Guest

    wrote:
    > I've done almost it. Check this out in web browser:
    >
    > file: index.xml
    >
    > <?xml version="1.0" encoding="ISO-8859-2"?>
    > <?xml-stylesheet type="text/xsl" href="tereska.xsl"?>


    [snip]

    It's not working for me. You might wish to specify an absolute URI in
    the xml-stylesheet deceleration. This isn't exactly XHTML though is it?


    --
    Brian O'Connor (ironcorona)
     
    ironcorona, May 14, 2006
    #11
  12. wrote:

    > I've done almost it. Check this out in web browser:


    application/xml D)ownload, or C)ancel

    .... oh very nice.

    Transforming XML to HTML (invalid HTML at that!) on the client side isn't
    very useful. Do it on the server - then it gets done once, instead of every
    time anyone tries to view it, and browser support gets much better.

    > .message { font-size: 12px;


    Pixel font sizes considered harmful.
    http://css-discuss.incutio.com/?page=FontSize

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, May 14, 2006
    #12
  13. Andy Dingley Guest

    wrote:
    > I'd like to make my own "XHTML tags library".


    Why? Is this a server-side or client-side operation?

    I'd advise against it for a client-side purpose (i.e. these tags get
    sent to the browser). In general a "browser" won't know what to do with
    them, so you gain nothing. It also stops your page being "standard HTML
    valid". Although you could do this legally and validly for XHTML as
    XML, that's not a practical proposition for the web.

    You also don't _need_ to do this, as intelligent use of class will
    allow all the subclassing of tags that you might need. Anything such as
    a property extension to tag function needs new attributes to be added
    to them, and here you're certainly off the edge of SGML-legacy browser
    support. You _can_ do this (and it has uses for DHTML) but the rules
    now are the same as they were in 1997 ("browsers safely ignore weird
    attributes, but you're on your own for what you do with them")

    If you're thinking server-side (i.e. these tags produce nothing more
    over the HTTP link than standard, valid HTML) then look at JSP and tag
    libraries. These are more than you're currently thinking of, but then
    any "need" for a custom tag library is probably based on a dynamic site
    with extensive content generation by code on the server.
     
    Andy Dingley, May 15, 2006
    #13
  14. Andy Dingley Guest

    wrote:

    > Now i must figureout how to embed this in XHTML document.


    Wrong approach. Instead use this format as an intermediate document and
    transform it server-side into real HTML / XHTML.

    > It is possible with namespaces


    Namespaces are an XML feature, so they don't work on the web (which is
    stuck in broken SGML-like for the forseeable future).
     
    Andy Dingley, May 15, 2006
    #14
    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. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    7
    Views:
    909
  3. chronos3d
    Replies:
    9
    Views:
    804
    Andy Dingley
    Dec 5, 2006
  4. KW
    Replies:
    2
    Views:
    632
    Andy Dingley
    Dec 15, 2006
  5. Usha2009
    Replies:
    0
    Views:
    1,147
    Usha2009
    Dec 20, 2009
Loading...

Share This Page