You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by "Gav...." <br...@brightontown.com.au> on 2007/07/03 14:56:19 UTC

MOTD template match query

In site-to-xhtml.xsl we have tests which to me say :-

when:
if test = x then do z
otherwise:
if test = y then do z

In other words, the below code snippet confuses me
Why not combine it to say

if test = x or test = y then do z

Or is there more to it than I have glimpsed at so far?

Thanks

Gav...



<xsl:if test="$config/motd">
      <xsl:for-each select="$config/motd/motd-option">
        <xsl:choose>
          <xsl:when test="@starts-with='true'">
            <xsl:if test="starts-with($path, @pattern)">
              <xsl:if test="motd-page/@location='page' or
motd-page/@location='both'">
                <div id="motd-area">
                  <xsl:value-of select="motd-page"/>
                  <xsl:if test="motd-page-url">
<xsl:text> (</xsl:text><a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="motd-page-url"/>
                    </xsl:attribute>
<xsl:text>More</xsl:text></a>
<xsl:text>)</xsl:text>
                  </xsl:if>
                </div>
              </xsl:if>
            </xsl:if>
          </xsl:when>
          <xsl:otherwise>
            <xsl:if test="contains($path, @pattern)">
              <xsl:if test="motd-page/@location='page' or
motd-page/@location='both'">
                <div id="motd-area">
                  <xsl:value-of select="motd-page"/>
                  <xsl:if test="motd-page-url">
<xsl:text> (</xsl:text><a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="motd-page-url"/>
                    </xsl:attribute>
<xsl:text>More</xsl:text></a>
<xsl:text>)</xsl:text>
                  </xsl:if>
                </div>
              </xsl:if>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:if>


Re: MOTD template match query

Posted by Ross Gardler <rg...@apache.org>.
On 03/07/07, Gav.... <br...@brightontown.com.au> wrote:
> In site-to-xhtml.xsl we have tests which to me say :-
>
> when:
> if test = x then do z
> otherwise:
> if test = y then do z
>
> In other words, the below code snippet confuses me
> Why not combine it to say
>
> if test = x or test = y then do z
>
> Or is there more to it than I have glimpsed at so far?

My interpretation is the same as yours. Probably a cut and paste jobby
that never got refactored.

Fastest way to see we you are right is, of course, to just try it.

Ross

Re: MOTD template match query

Posted by David Crossley <cr...@apache.org>.
Gav... wrote:
> who="David Crossley"
> > Ross Gardler wrote:
> >> David Crossley wrote:
> >> >Gav.... wrote:
> >> >>
> >> >> In site-to-xhtml.xsl we have tests which to me say :-
> >> >>
> >> >> when:
> >> >> if test = x then do z
> >> >> otherwise:
> >> >> if test = y then do z
> >> >>
> >> >> In other words, the below code snippet confuses me
> >> >> Why not combine it to say
> >> >>
> >> >> if test = x or test = y then do z
> >> >>
> >> >> Or is there more to it than I have glimpsed at so far?
> >> >
> >> >Would you please give me more clues as to which parts
> >> >that you cannot understand.
> >>
> >> :-) It took me a while to figure out what Gavin meant...
> >>
> >> In Gavins psuedo code above
> >>
> >> "when" represents <xsl:when test="@starts-with='true'">
> >>
> >> "otherwise" represents the following <xsl:otherwise>
> >>
> >> "if test = x" represents <xsl:if test="starts-with($path, @pattern)">
> >>
> >> "if test = y" represents <xsl:if test="contains($path, @pattern)">
> >>
> >> "z" represents everything inside the above <xsl:if> statements
> >>
> >> The bit of XSL this refers to is copied below.
> >
> > Remember that we are allowing the pattern to be
> > either anchored at beginning of the URI or contained
> > anywhere within the URI. We also need to match the
> > pattern for the URI being processed. We also need
> > to only place the message if it is configured to be
> > on the face of the page.
> >
> > Other similar sections of code deal with placing it
> > in the left-hand panel, and with placing a message
> > in the title.
> >
> > Here is the pseudo-code ...
> >
> > -------------
> > If MOTD is configured
> >  For each option
> >
> >   If @starts-with is true
> >    Then If URI has the pattern anchored at beginning
> >     Then If location is face-of-page
> >      Place the motd message
> >      If there is a link
> >       Then create a link from "More"
> >
> >   If @starts-with is not true
> >    Then If URI contains the pattern
> >     Then do the same as above
> >
> >  End of foreach option
> > -------------
> >
> > I don't see anything wrong with that, nor can i see
> > how to do it better.
> 
> Ok, fair enough, all I saw was repeated code and wondered if it could be
> cleaned up a little, the speed cost is negligable so we could leave it and
> concentrate on the real problem.
> 
> Using your pseudo code my thoughts on improving it was :-
> 
>  -------------
>  If MOTD is configured
>   For each option
> 
>     If URI has the pattern anchored at beginning or contains the pattern
>      Then If location is face-of-page
>       Place the motd message
>       If there is a link
>        Then create a link from "More"
> 
>   End of foreach option
>  -------------
> 
> I still don't see why this wouldn't work ( and it removed repeated code),
> but no matter, I'll try it later on and see ...

As long as it still provides the ability to match
at either the start of URI, or alternatively anywhere
within. You would need to test it in a wide variety
of situations. Seems like a lot of effort.

-David

> ...- but it is just something I
> spotted whilst working on the main problem of positioning MOTD etc in a
> new container <div> and not important.
> 
> Gav...

Re: MOTD template match query

Posted by "Gav..." <br...@brightontown.com.au>.
<quote who="David Crossley">
> Ross Gardler wrote:
>> David Crossley wrote:
>> >Gav.... wrote:
>> >>
>> >> In site-to-xhtml.xsl we have tests which to me say :-
>> >>
>> >> when:
>> >> if test = x then do z
>> >> otherwise:
>> >> if test = y then do z
>> >>
>> >> In other words, the below code snippet confuses me
>> >> Why not combine it to say
>> >>
>> >> if test = x or test = y then do z
>> >>
>> >> Or is there more to it than I have glimpsed at so far?
>> >
>> >Would you please give me more clues as to which parts
>> >that you cannot understand.
>>
>> :-) It took me a while to figure out what Gavin meant...
>>
>> In Gavins psuedo code above
>>
>> "when" represents <xsl:when test="@starts-with='true'">
>>
>> "otherwise" represents the following <xsl:otherwise>
>>
>> "if test = x" represents <xsl:if test="starts-with($path, @pattern)">
>>
>> "if test = y" represents <xsl:if test="contains($path, @pattern)">
>>
>> "z" represents everything inside the above <xsl:if> statements
>>
>> The bit of XSL this refers to is copied below.
>
> Remember that we are allowing the pattern to be
> either anchored at beginning of the URI or contained
> anywhere within the URI. We also need to match the
> pattern for the URI being processed. We also need
> to only place the message if it is configured to be
> on the face of the page.
>
> Other similar sections of code deal with placing it
> in the left-hand panel, and with placing a message
> in the title.
>
> Here is the pseudo-code ...
>
> -------------
> If MOTD is configured
>  For each option
>
>   If @starts-with is true
>    Then If URI has the pattern anchored at beginning
>     Then If location is face-of-page
>      Place the motd message
>      If there is a link
>       Then create a link from "More"
>
>   If @starts-with is not true
>    Then If URI contains the pattern
>     Then do the same as above
>
>  End of foreach option
> -------------
>
> I don't see anything wrong with that, nor can i see
> how to do it better.

Ok, fair enough, all I saw was repeated code and wondered if it could be
cleaned up a little, the speed cost is negligable so we could leave it and
concentrate on the real problem.

Using your pseudo code my thoughts on improving it was :-

 -------------
 If MOTD is configured
  For each option

    If URI has the pattern anchored at beginning or contains the pattern
     Then If location is face-of-page
      Place the motd message
      If there is a link
       Then create a link from "More"

  End of foreach option
 -------------

I still don't see why this wouldn't work ( and it removed repeated code),
but no matter, I'll try it later on and see - but it is just something I
spotted whilst working on the main problem of positioning MOTD etc in a
new container <div> and not important.

Gav...


>
> -David
>
>> >> <xsl:if test="$config/motd">
>> >>       <xsl:for-each select="$config/motd/motd-option">
>> >>         <xsl:choose>
>> >>           <xsl:when test="@starts-with='true'">
>> >>             <xsl:if test="starts-with($path, @pattern)">
>> >>               <xsl:if test="motd-page/@location='page' or
>> >> motd-page/@location='both'">
>> >>                 <div id="motd-area">
>> >>                   <xsl:value-of select="motd-page"/>
>> >>                   <xsl:if test="motd-page-url">
>> >> <xsl:text> (</xsl:text><a>
>> >>                     <xsl:attribute name="href">
>> >>                       <xsl:value-of select="motd-page-url"/>
>> >>                     </xsl:attribute>
>> >> <xsl:text>More</xsl:text></a>
>> >> <xsl:text>)</xsl:text>
>> >>                   </xsl:if>
>> >>                 </div>
>> >>               </xsl:if>
>> >>             </xsl:if>
>> >>           </xsl:when>
>> >>           <xsl:otherwise>
>> >>             <xsl:if test="contains($path, @pattern)">
>> >>               <xsl:if test="motd-page/@location='page' or
>> >> motd-page/@location='both'">
>> >>                 <div id="motd-area">
>> >>                   <xsl:value-of select="motd-page"/>
>> >>                   <xsl:if test="motd-page-url">
>> >> <xsl:text> (</xsl:text><a>
>> >>                     <xsl:attribute name="href">
>> >>                       <xsl:value-of select="motd-page-url"/>
>> >>                     </xsl:attribute>
>> >> <xsl:text>More</xsl:text></a>
>> >> <xsl:text>)</xsl:text>
>> >>                   </xsl:if>
>> >>                 </div>
>> >>               </xsl:if>
>> >>             </xsl:if>
>> >>           </xsl:otherwise>
>> >>         </xsl:choose>
>> >>       </xsl:for-each>
>> >>     </xsl:if>
>> >>
>> >
>> >
>>
>>
>> --
>> --
>> Ross Gardler
>>
>> OSS Watch - awareness and understanding of open source software
>> development and use in education
>> http://www.oss-watch.ac.uk
>


-- 
Gav...


Re: MOTD template match query

Posted by David Crossley <cr...@apache.org>.
Ross Gardler wrote:
> David Crossley wrote:
> >Gav.... wrote:
> >>
> >> In site-to-xhtml.xsl we have tests which to me say :-
> >>
> >> when:
> >> if test = x then do z
> >> otherwise:
> >> if test = y then do z
> >>
> >> In other words, the below code snippet confuses me
> >> Why not combine it to say
> >>
> >> if test = x or test = y then do z
> >>
> >> Or is there more to it than I have glimpsed at so far?
> >
> >Would you please give me more clues as to which parts
> >that you cannot understand.
> 
> :-) It took me a while to figure out what Gavin meant...
> 
> In Gavins psuedo code above
> 
> "when" represents <xsl:when test="@starts-with='true'">
> 
> "otherwise" represents the following <xsl:otherwise>
> 
> "if test = x" represents <xsl:if test="starts-with($path, @pattern)">
> 
> "if test = y" represents <xsl:if test="contains($path, @pattern)">
> 
> "z" represents everything inside the above <xsl:if> statements
> 
> The bit of XSL this refers to is copied below.

Remember that we are allowing the pattern to be
either anchored at beginning of the URI or contained
anywhere within the URI. We also need to match the
pattern for the URI being processed. We also need
to only place the message if it is configured to be
on the face of the page.

Other similar sections of code deal with placing it
in the left-hand panel, and with placing a message
in the title.

Here is the pseudo-code ...

-------------
If MOTD is configured
 For each option

  If @starts-with is true
   Then If URI has the pattern anchored at beginning
    Then If location is face-of-page
     Place the motd message
     If there is a link
      Then create a link from "More"

  If @starts-with is not true
   Then If URI contains the pattern
    Then do the same as above

 End of foreach option
-------------

I don't see anything wrong with that, nor can i see
how to do it better.

-David
 
> >> <xsl:if test="$config/motd">
> >>       <xsl:for-each select="$config/motd/motd-option">
> >>         <xsl:choose>
> >>           <xsl:when test="@starts-with='true'">
> >>             <xsl:if test="starts-with($path, @pattern)">
> >>               <xsl:if test="motd-page/@location='page' or
> >> motd-page/@location='both'">
> >>                 <div id="motd-area">
> >>                   <xsl:value-of select="motd-page"/>
> >>                   <xsl:if test="motd-page-url">
> >> <xsl:text> (</xsl:text><a>
> >>                     <xsl:attribute name="href">
> >>                       <xsl:value-of select="motd-page-url"/>
> >>                     </xsl:attribute>
> >> <xsl:text>More</xsl:text></a>
> >> <xsl:text>)</xsl:text>
> >>                   </xsl:if>
> >>                 </div>
> >>               </xsl:if>
> >>             </xsl:if>
> >>           </xsl:when>
> >>           <xsl:otherwise>
> >>             <xsl:if test="contains($path, @pattern)">
> >>               <xsl:if test="motd-page/@location='page' or
> >> motd-page/@location='both'">
> >>                 <div id="motd-area">
> >>                   <xsl:value-of select="motd-page"/>
> >>                   <xsl:if test="motd-page-url">
> >> <xsl:text> (</xsl:text><a>
> >>                     <xsl:attribute name="href">
> >>                       <xsl:value-of select="motd-page-url"/>
> >>                     </xsl:attribute>
> >> <xsl:text>More</xsl:text></a>
> >> <xsl:text>)</xsl:text>
> >>                   </xsl:if>
> >>                 </div>
> >>               </xsl:if>
> >>             </xsl:if>
> >>           </xsl:otherwise>
> >>         </xsl:choose>
> >>       </xsl:for-each>
> >>     </xsl:if>
> >>
> >
> >
> 
> 
> -- 
> --
> Ross Gardler
> 
> OSS Watch - awareness and understanding of open source software
> development and use in education
> http://www.oss-watch.ac.uk

Re: MOTD template match query

Posted by Ross Gardler <rg...@apache.org>.
On 04/07/07, David Crossley <cr...@apache.org> wrote:
> Gav.... wrote:
> > In site-to-xhtml.xsl we have tests which to me say :-
> >
> > when:
> > if test = x then do z
> > otherwise:
> > if test = y then do z
> >
> > In other words, the below code snippet confuses me
> > Why not combine it to say
> >
> > if test = x or test = y then do z
> >
> > Or is there more to it than I have glimpsed at so far?
>
> Would you please give me more clues as to which parts
> that you cannot understand.

:-) It took me a while to figure out what Gavin meant...

In Gavins psuedo code above

"when" represents <xsl:when test="@starts-with='true'">

"otherwise" represents the following <xsl:otherwise>

"if test = x" represents <xsl:if test="starts-with($path, @pattern)">

"if test = y" represents <xsl:if test="contains($path, @pattern)">

"z" represents everything inside the above <xsl:if> statements

The bit of XSL this refers to is copied below.

> > <xsl:if test="$config/motd">
> >       <xsl:for-each select="$config/motd/motd-option">
> >         <xsl:choose>
> >           <xsl:when test="@starts-with='true'">
> >             <xsl:if test="starts-with($path, @pattern)">
> >               <xsl:if test="motd-page/@location='page' or
> > motd-page/@location='both'">
> >                 <div id="motd-area">
> >                   <xsl:value-of select="motd-page"/>
> >                   <xsl:if test="motd-page-url">
> > <xsl:text> (</xsl:text><a>
> >                     <xsl:attribute name="href">
> >                       <xsl:value-of select="motd-page-url"/>
> >                     </xsl:attribute>
> > <xsl:text>More</xsl:text></a>
> > <xsl:text>)</xsl:text>
> >                   </xsl:if>
> >                 </div>
> >               </xsl:if>
> >             </xsl:if>
> >           </xsl:when>
> >           <xsl:otherwise>
> >             <xsl:if test="contains($path, @pattern)">
> >               <xsl:if test="motd-page/@location='page' or
> > motd-page/@location='both'">
> >                 <div id="motd-area">
> >                   <xsl:value-of select="motd-page"/>
> >                   <xsl:if test="motd-page-url">
> > <xsl:text> (</xsl:text><a>
> >                     <xsl:attribute name="href">
> >                       <xsl:value-of select="motd-page-url"/>
> >                     </xsl:attribute>
> > <xsl:text>More</xsl:text></a>
> > <xsl:text>)</xsl:text>
> >                   </xsl:if>
> >                 </div>
> >               </xsl:if>
> >             </xsl:if>
> >           </xsl:otherwise>
> >         </xsl:choose>
> >       </xsl:for-each>
> >     </xsl:if>
> >
>
>


-- 
--
Ross Gardler

OSS Watch - awareness and understanding of open source software
development and use in education
http://www.oss-watch.ac.uk

Re: MOTD template match query

Posted by David Crossley <cr...@apache.org>.
Gav.... wrote:
> In site-to-xhtml.xsl we have tests which to me say :-
> 
> when:
> if test = x then do z
> otherwise:
> if test = y then do z
> 
> In other words, the below code snippet confuses me
> Why not combine it to say
> 
> if test = x or test = y then do z
> 
> Or is there more to it than I have glimpsed at so far?

Would you please give me more clues as to which parts
that you cannot understand.

-David

> <xsl:if test="$config/motd">
>       <xsl:for-each select="$config/motd/motd-option">
>         <xsl:choose>
>           <xsl:when test="@starts-with='true'">
>             <xsl:if test="starts-with($path, @pattern)">
>               <xsl:if test="motd-page/@location='page' or
> motd-page/@location='both'">
>                 <div id="motd-area">
>                   <xsl:value-of select="motd-page"/>
>                   <xsl:if test="motd-page-url">
> <xsl:text> (</xsl:text><a>
>                     <xsl:attribute name="href">
>                       <xsl:value-of select="motd-page-url"/>
>                     </xsl:attribute>
> <xsl:text>More</xsl:text></a>
> <xsl:text>)</xsl:text>
>                   </xsl:if>
>                 </div>
>               </xsl:if>
>             </xsl:if>
>           </xsl:when>
>           <xsl:otherwise>
>             <xsl:if test="contains($path, @pattern)">
>               <xsl:if test="motd-page/@location='page' or
> motd-page/@location='both'">
>                 <div id="motd-area">
>                   <xsl:value-of select="motd-page"/>
>                   <xsl:if test="motd-page-url">
> <xsl:text> (</xsl:text><a>
>                     <xsl:attribute name="href">
>                       <xsl:value-of select="motd-page-url"/>
>                     </xsl:attribute>
> <xsl:text>More</xsl:text></a>
> <xsl:text>)</xsl:text>
>                   </xsl:if>
>                 </div>
>               </xsl:if>
>             </xsl:if>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:for-each>
>     </xsl:if>
>