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

A. Pagaltzis pagaltzis at gmx.de
Thu Apr 13 13:46:07 CEST 2006


* John Beppu <john.beppu at gmail.com> [2006-04-13 12:55]:
> DISCLAIMER:  I'm an XSLT n00b.

Some quick untested cleanups…

I don’t like the `copy-of`s that are still left, but I’d need to
test it before I could make more tweaks and I’m disinclined right
now. In general, the right way to use XSLT is to have an identity
transform as the default and use `apply-templates` to drive all
changes, so that every part of the result tree is exposed to rule
application. `copy-of` output cannot be transformed any further.

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

    <xsl:output
        method="xml"
        indent="yes"
        omit-xml-declaration="yes"
    />

    <xsl:key name="span" match="span" use="@id" />

    <!-- identity transform -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="form">
        <form>
            <xsl:apply-templates select="@*" />
            <table width="100%">
                <colgroup span="1" width="15%" />
                <colgroup span="1" width="35%" />
                <colgroup span="1" width="50%" />
                <tbody>
                    <xsl:apply-templates select="node()" />
                </tbody>
            </table>
        </form>
    </xsl:template>

    <xsl:template match="label">
        <tr>
            <td class="label">
                <xsl:apply-templates />
            </td>
            <td class="value">
                <xsl:apply-templates select="input|textarea|select" />
                <xsl:copy-of select="key( 'span', concat( @for, '_descriptions' ) )" />
            </td>
            <td>
                <xsl:copy-of select="key( 'span', concat( @for, '_errors' ) )" />
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="input[@type='submit']">
        <tr>
            <td class="label"></td>
            <td class="value" colspan="2">
                <xsl:apply-templates />
            </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:value-of select="key( 'span', concat( @id, '_value' ) )" />
            </td>
        </tr>
    </xsl:template>

    <!-- drop -->
    <xsl:template match="legend|span[@class='span_value']">

    </xsl:stylesheet>


Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list