How to create custom XHTML tag?

J

janecki

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!
 
I

ironcorona

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.
 
J

janecki

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

ironcorona

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.
 
D

David Dorward

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.
 
D

David Segall

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.
 
T

Toby Inkster

janecki said:
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; }
 
A

Alan J. Flavell

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
 
J

janecki

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>[email protected]</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.
 
I

ironcorona

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.
 
I

ironcorona

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?
 
D

David Dorward

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
 
A

Andy Dingley

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.
 
A

Andy Dingley

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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,865
Latest member
AveryHamme

Latest Threads

Top