Wendell,
I choose a simple example (login page) to post this question. But other
pages are more complex. The output is meant for Browsers to transform client
side
Currently the input XML structure has a <form> tag which can have either:
1) "presentation tags" like <text>, <image>, etc which require to fill the
whole width (in the HTML, these are already placed in <div> to get its own
line WITHOUT any <table>)
2) "entry tags" like <input>, <password>, <checkbox>, etc which require to
be separated into a label and a value (in HTML, I want these to be placed in
a <table>, EITHER a new table if the previous tag was a "presentation tag"
OR a new row in the previous table if the previous tag was an "entry tag")
The special considerations for this are:
A) there can be any sequence of "presentation tags" and "entry tags"
B) if there are "presentation tags" in-between groups of "entry tags", then
each separated group of entry tags will have their own table.
C) I do _not_ want to put "presentation tags" in a table in anyway (eg. use
a single column with "colspan=2")
As for why is my output XHTML, it doesn't really matter to this question...
let's just treat the output as HTML.
Regards,
Daniel
-----Original Message-----
From: Wendell Piez [mailto:wapiez(_at_)mulberrytech(_dot_)com]
Sent: Wednesday, 26 May, 2004 11:57 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Grouping into a table (for vertical alignment)
Daniel,
What assumptions, if any, can we make about the proximity of <input> and
<password> elements? Can either appear independently of the other? Can
arbitrary <text> elements appear between them at any point? How many can
there be? (You've indicated that more than one <input> can appear, but not
said whether none can appear, or whether there will always be a <password>,
or how many <password> elements there could be.)
These are relevant since the solution will be to produce one or more tables
in a template matching <content> or perhaps a template matching <input> or
<password> (which would then pick up certain of the matching element's
siblings to tuck them into the table), but this raises the question of how
and whether <text>, <input> and <password> elements should be grouped
together in a table. The precise logic to do this will be easier to
determine if we know what kinds of constraints operate over the input.
If you have a content model for your <content> element (from a DTD or
schema), this would be a big help.
Cheers,
Wendell
At 01:20 AM 5/26/2004, you wrote:
Thanks for your reply.
Is your problem harder than
Yes it is. I do not want to have 2 separate tables (one for the 'input' and
one for the 'password'), I want to use the a single table if both elements
need tables, and not add a table if the element is a 'text'. And its need
to
be generic so that if I add in more 'input' or 'text' is will make tables
accordingly.
I try to be a bit more clear, I included the desired output this time.
XML (Input):
.
.
.
<form>
<name>form</name>
<action>submit.do</action>
<method>post</method>
<content>
<text>
<value>Please enter your Name and Password.</value>
<class>instruction</class>
</text>
<input>
<name>username</name>
<label>Name: </label>
<value></value>
<class>mandatory</class>
</input>
<password>
<name>password</name>
<label>Password :</label>
<value></value>
<class>mandatory</class>
</password>
<text>
<value>All attempts are logged.</value>
<class>warning</class>
</text>
</content>
</form>
.
.
.
XHTML (Desired Output)
.
.
.
<form name="form" action="submit.do" method="post">
<div class="instruction">Please enter your Name and Password.</div>
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="username" value=""
class="mandatory"></input></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" value=""
class="mandatory"></input></td>
</tr>
<table>
<div class="warning">All attempts are logged..</div>
</form>
.
.
.
XSLT (which does not create the table):
.
.
.
<xsl:template match="form">
<form>
<xsl:for-each select="name | action | method">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates"/>
</form>
</xsl:template>
<xsl:template match="text">
<div>
<xsl:for-each select="class">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:value-of select="value"/>
</div>
</xsl:template>
<xsl:template match="label">
<xsl:value-of select="."/>
<xsl:text>: </xsl:text>
</xsl:template>
<xsl:template match="input">
<xsl:apply-templates select="label"/>
<input>
<xsl:attribute name="type">
<xsl:text>text</xsl:text>
</xsl:attribute>
<xsl:for-each select="name | value | class">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</input>
</xsl:template>
<xsl:template match="password">
<xsl:apply-templates select="label"/>
<input>
<xsl:attribute name="type">
<xsl:text>password</xsl:text>
</xsl:attribute>
<xsl:for-each select="name | value | class">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</input>
</xsl:template>
.
.
.
Regards,
Daniel
-----Original Message-----
From: Wendell Piez [mailto:wapiez(_at_)mulberrytech(_dot_)com]
Sent: Tuesday, 25 May, 2004 10:56 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Grouping into a table (for vertical alignment)
Daniel,
Is your problem harder than
<xsl:template match="input">
<table>
<tr>
<td>
<xsl:apply-templates select="label"/>
</td>
<td>
<input>
<xsl:attribute name="type">
<xsl:text>text</xsl:text>
</xsl:attribute>
<xsl:for-each select="name | value | class">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</input>
</td>
</tr>
</table>
</xsl:template>
?
If so, could you be more specific as to what results you want to get?
Cheers,
Wendell
At 09:11 AM 5/24/2004, you wrote:
Hi,
I am trying to make a generic XSLT for converting XML into XHTML.
I want to put my output into a <table> for vertically aligning the
'label'
and 'input' fields.