Re: [xsl] Standards checkers for XSLT

Subject: Re: [xsl] Standards checkers for XSLT
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 24 Nov 2006 17:29:33 -0800
Hi Robert,

On 11/24/06, Robert Koberg <rob@xxxxxxxxxx> wrote:
Dimitre Novatchev wrote:
> Briefly,
>
>  1. Indentation. A stylesheet is an xml document, so the same
> formatting guidelines apply.
>
>  2. Limited lines' width so that the whole code can be read on the
> screen without horizontal scrolling.

Is this better:

<p>some 80 chars
some other 80 chars
more 80 chars</p>

or this:

<p>some 80 chars some other 80 chars more 80 chars</p>

?

Certainly, the recommendation to use limited line's widhts is in the context of "where this can be done". Most of the times one can limit the width without significantly changing the contents of the document.


> > 3. Consistent use of naming rules: > > -- camelCase notation

bah...


Dr. Kay already explained that this is *one* possible style, which
already is used by the vocabulary of xml schema. Therefore, we cannot
completely avoid it, even if we did want to.

Using hyphens or underscores to separate words in a name may be more
readable, but has the side effect of occupying more space and
requiring more keystrokes.




> > -- pParameter, vVariable, ... etc. Hungarian notation examples. > > -- the names themselves should express the role of the variable > in the transformation. > > -- use of blank lines to separate sections of equally indented > blocks of code that have separate meaning/roles. > > -- vertical allignment of long XPath expressions > > > 4. Preference to XPath 2.0 code over XSLT 2.0 code.

What does this mean?

This is XSLT-style code:


     <xsl:choose>
        <xsl:when test="not($pList)">
           <xsl:copy-of select="$pA0"/>
        </xsl:when>
        <xsl:otherwise>

           <xsl:variable name="vFunResult">
             <xsl:apply-templates select="$pFunc[1]" mode="f:FXSL">
               <xsl:with-param name="arg0" select="$pFunc[position() > 1]"/>
               <xsl:with-param name="arg1" select="$pA0"/>
               <xsl:with-param name="arg2" select="$pList[1]"/>
             </xsl:apply-templates>
           </xsl:variable>

           <xsl:call-template name="foldl">
	      <xsl:with-param name="pFunc" select="$pFunc"/>
	      <xsl:with-param name="pList" select="$pList[position() > 1]"/>
	      <xsl:with-param name="pA0" select="$vFunResult/node()"/>
           </xsl:call-template>
        </xsl:otherwise>
     </xsl:choose>


and this is the same in XPath-style code:


     <xsl:sequence select=
            "if (empty($pList))
                 then
                     $pA0
                 else
                     f:foldl($pFunc,
                             f:apply($pFunc, $pA0, $pList[1]),
                             $pList[position() > 1]
                             )"/>




-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play





-Rob

Current Thread