[Catalyst] HTML::Widget and output into a html table

John Beppu john.beppu at gmail.com
Thu Apr 13 13:20:49 CEST 2006


While I was writing the XSLT, the thought of doing it with Perl crossed my
mind many times.  ;-)

I don't normally get along too well with XML, but I thought I'd give XSLT a
chance since it's whole reason for existence is to do these kinds of
transformations.  I think my biggest motivation was the desire to see code
like:

[% USE widget_stylesheet = XSLT('stylesheet.xsl');
  widget.as_xml | $widget_stylesheet %]

in action.  I was impressed when mst posted that, and I wanted to see if it
would really work.


On 4/13/06, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
>
> I would rather make this transformation with Perl and one of the XPath
> libraries: XML::XPath
> http://search.cpan.org/~msergeant/XML-XPath-1.13/XPath.pm or
> Template::Plugin::XML::XPath -
>
> http://search.cpan.org/~abw/Template-Toolkit-2.14/lib/Template/Plugin/XML/XPath.pm
> .
>
> -- Zbyszek
>
> On 4/13/06, John Beppu <john.beppu at gmail.com> wrote:
> > DISCLAIMER:  I'm an XSLT n00b.
> >
> > With that out of the way, I came up with the following .xsl stylesheet
> to
> > take HTML::Widget's output and turn it into tables.  It's a work in
> > progress, but I think some people might appreciate this.
> >
> >
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >
> >   <xsl:output method="xml" indent="yes" />
> >   <xsl:output omit-xml-declaration="yes" />
> >
> >   <xsl:key name="span" match="span" use="@id" />
> >
> >   <xsl:template match="form">
> >     <form class="{@class}" id="{@id}" action="{@action}"
> method="{@method}">
> >       <table width="100%">
> >     <colgroup span="1" width="15%" />
> >     <colgroup span="1" width="35%" />
> >     <colgroup span="1" width="50%" />
> >
> >     <tbody>
> >       <xsl:apply-templates />
> >     </tbody>
> >
> >       </table>
> >     </form>
> >   </xsl:template>
> >
> >   <xsl:template match="legend">
> >     <!-- omit -->
> >   </xsl:template>
> >
> >   <xsl:template match="label">
> >     <tr>
> >       <td class="label"><xsl:apply-templates/></td>
> >       <td class="value">
> >     <xsl:copy-of select="input" />
> >     <xsl:copy-of select="textarea" />
> >     <xsl:copy-of select="select" />
> >     <xsl:variable name="description_span_id" select="concat(@for,
> > '_descriptions')" />
> >     <xsl:copy-of select="key('span', $description_span_id)" />
> >       </td>
> >       <td>
> >     <xsl:variable name="error_span_id" select="concat(@for, '_errors')"
> />
> >     <xsl:copy-of select="key('span', $error_span_id)" />
> >       </td>
> >     </tr>
> >   </xsl:template>
> >
> >   <xsl:template match="input[@type='hidden']">
> >     <xsl:copy-of select="." />
> >   </xsl:template>
> >
> >   <xsl:template match="input[@type='submit']">
> >     <tr>
> >       <td class="label"></td>
> >       <td class="value" colspan="2">
> >     <xsl:copy-of select="." />
> >       </td>
> >     </tr>
> >   </xsl:template>
> >
> >   <!--
> >   I use span elements with class span_label and span_value to
> >   represent values that I only want to display (and not edit).
> >   -->
> >   <xsl:template match="//span[@class='span_label']">
> >     <tr>
> >       <td class="label">
> >     <xsl:apply-templates/>
> >       </td>
> >       <td class="value" colspan="2">
> >     <xsl:variable name="value_id" select="concat(@id, '_value')" />
> >     <xsl:value-of select="key('span', $value_id)" />
> >       </td>
> >     </tr>
> >   </xsl:template>
> >
> >   <xsl:template match="//span[@class='span_value']">
> >     <!-- omit -->
> >   </xsl:template>
> >
> > </xsl:stylesheet>
> >
> >
> >
> >
> > On 2/9/06, John Lifsey - Contractor - <john.lifsey at nrl.navy.mil> wrote:
> > > Seeing those two lines of code is about the best thing thats happened
> to
> > > my life with Catalyst since HTML::Widget.
> > > ++
> > >
> > > Matt S Trout wrote:
> > > > On Thu, Feb 09, 2006 at 11:56:59AM -0800, John Wang wrote:
> > > >
> > > >> On 2/9/06, Pfister Andreas <Pfister_Andreas at hispeed.ch> wrote:
> > > >>
> > > >>> I like to create html form <form> dynamicly with HTML::Widget and
> to
> > have
> > > >>> a output like
> > > >>> <table>
> > > >>> <form xxxxx>
> > > >>> *<tr><td>*INPUT 1*</td><td>*<input type="text">*<td></tr>*
> > > >>> <tr><td>INPUT 1<........................
> > > >>>
> > > >>> Any hints how to get this output ? I tested the css example but I
> was
> > not
> > > >>> so happy with output.
> > > >>>
> > > >> Are you not happy with the default CSS or the DOM structure? If the
> > default
> > > >> CSS is bothering you, learning CSS layout would be the way to go.
> If
> > the DOM
> > > >> structure doesn't let you do what you want with CSS, perhaps the
> DOM
> > > >> structure can be modified.
> > > >>
> > > >> I don't think H::W supports tables so if you want to use tables for
> > layout,
> > > >> you may need to do form generation outside of H::W but you can
> still
> > use it
> > > >> for validation.
> > > >>
> > > >
> > > > [% USE widget_stylesheet = XSLT('stylesheet.xsl');
> > > >    widget.as_xml | $widget_stylesheet %]
> > > >
> > > >
> > >
> > > _______________________________________________
> > > Catalyst mailing list
> > > Catalyst at lists.rawmode.org
> > > http://lists.rawmode.org/mailman/listinfo/catalyst
> > >
> >
> >
> > _______________________________________________
> > Catalyst mailing list
> > Catalyst at lists.rawmode.org
> > http://lists.rawmode.org/mailman/listinfo/catalyst
> >
> >
> >
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060413/1a1e4f7f/attachment-0001.htm 


More information about the Catalyst mailing list