[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSLT templates for HTML/XHTML elements


Subject: Re: [xsl] XSLT templates for HTML/XHTML elements
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Wed, 27 Feb 2002 09:14:50 -0800

Hi,

If you can use CSS you can do something like the below. You pretty much use
this once and just change the CSS from project to project. Of course this is
just a component (xsl:include) that fits into a page layout. E.g. the
regualr article match produces a standard article and the "floater" article
produces something that stands out more or less depending on how you set the
CSS. You can have multiple articles on a page, in other words.

<?xml version="1.0" encoding="iso-8859-1"?>

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

<xsl:template match="article">

   <xsl:param name="xml_id"/>

    <DIV id="{$xml_id}" class="article">
        <SPAN class="wide">

            <xsl:apply-templates/>

        </SPAN>
    </DIV>

</xsl:template>

<xsl:template match="article" mode="floater">

    <xsl:param name="xml_id"/>

    <DIV class="article" id="{$xml_id}">

         <SPAN class="floater">

            <xsl:apply-templates/>

        </SPAN>

    </DIV>

</xsl:template>

<xsl:template match="section">

   <SPAN id="{generate-id()}" class="section">

      <xsl:apply-templates/>

   </SPAN>

</xsl:template>

<xsl:template match="title">

    <DIV id="{generate-id()}">

        <xsl:apply-templates/>

    </DIV>

</xsl:template>

<xsl:template match="para">


    <DIV id="{generate-id()}">

        <xsl:apply-templates/>

    </DIV>

</xsl:template>

<xsl:template match="img" >

        <IMG
            ID="{generate-id()}"
            ALIGN="{@align}"
            SRC="{$context}/images/{@fileref}"
            ALT="{@alt}" />



</xsl:template>

<xsl:template match="strong">

   <ID="{generate-id()}" >

     <xsl:apply-templates/>

   </STRONG>

</xsl:template>

<xsl:template match="em">

   <EM ID="{generate-id()}">

     <xsl:apply-templates/>

   </EM>

</xsl:template>

<xsl:template match="u">

   <U ID="{generate-id()}" >

     <xsl:apply-templates/>

   </U>

</xsl:template>

<xsl:template match="ol">

       <OL>

         <xsl:apply-templates/>

       </OL>

</xsl:template>

<xsl:template match="ul">

       <UL>

         <xsl:apply-templates/>

       </UL>

</xsl:template>

<xsl:template match="li">

   <LI ID="{generate-id()}">

     <xsl:apply-templates/>

   </LI>

</xsl:template>

<xsl:template match="link">

    <xsl:variable name="href">
        <xsl:choose>
            <xsl:when test="@link_out">
                <xsl:value-of select="@link_out"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$derived_href_from_somewhere"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

   <A TARGET="{@target}" ID="{generate-id()}" HREF="{$href}">

     <xsl:apply-templates/>

   </A>

</xsl:template>

<xsl:template match="pre">

   <PRE>

     <xsl:apply-templates/>

   </PRE>

</xsl:template>

</xsl:stylesheet>














----- Original Message -----
From: "Andrew Mottershead" <andrew@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, February 27, 2002 8:51 AM
Subject: [xsl] XSLT templates for HTML/XHTML elements


> Hello there folks,
>
> Not wanting to re-invent the wheel I want to find out whether there is a
> resource somewhere with xslt snippits for the basic html/xhtml
> constructs? E.g. a hyperlink would be similar to:
>
> <xsl:template name="StandardLink">
> <xsl:param name="Label"/>
> <xsl:param name="Linktext"/>
> <xsl:param name="Sessionid"/>
> <xsl:param name="Target"/>
> <a>
> <xsl:attribute name="Target"><xsl:value-of
> select="$Target"/></xsl:attribute>
> <xsl:attribute name="href"><xsl:value-of
> select="concat('default.asp?Label=',$Label,'&amp;Nextstep=Tweb.',$Nextst
> ep,'&amp;Sessionid=',$Sessionid,)"/></xsl:attribute>
> <xsl:value-of select="$Linktext"/>
> </xsl:template>
>
> I need similar for all the major form elements eg. checkbox, dropdown
> listbox, hidden field, submit button, you name it otherwise I've got a
> long night ahead of me creating them all from scratch. Any ideas?
>
> Also does anyone know of any wysiwyg xhtml editors shich allow for
> customisable wrappers?
>
> regards
>
> Andrew Mottershead
> Web Developer
> Mindstream
>
> email: andrew@xxxxxxxxxxxxxxxx
> tel: 01743 718198
> web: www.mindstream.co.uk
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.325 / Virus Database: 182 - Release Date: 19/02/2002
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords