[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Efficient Templating - Concise Template Design

Subject: RE: Efficient Templating - Concise Template Design
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 21 Feb 2005 10:49:18 -0000
xsl template design
> -----Original Message-----
> From: Adam J Knight [mailto:adam@xxxxxxxxxxxxxxxxx]
> Sent: 21 February 2005 10:02
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Efficient Templating - Concise Template Design
>
> Hi guys,
>
>
>
> I have created the template below (a part of my first ever complete
> stylesheet). To me it seems a little long winded, and I
> wonder if it could
> be put more concisely. Be a better example of template design.
>

If we take your logic starting at
<xsl:when test="@id = $id or descendant::tree_node/@id = $id">

you seem to have three conditions

A: @id = $id
B: descendant::tree_node/@id = $id
C: $node = 'collapse'

and the decision table is

A   B   C   node     gif

y   ?   y   expand   close
y   ?   n   collapse open
n   y   ?   collapse open
n   n   ?   expand   close

which translates into

if ((A and C) or (not(A) and not(B)))
  then (expand;open)
  else (collapse;close)

I might not have read your logic carefully enough, of course. But it seems
to be essentially a question of simplifying the boolean logic, nothing
specific to XSLT.

Michael Kay
http://www.saxonica.com/


>
> <xsl:template match="tree_node">
>
>   <tr>
>      <td>
>        <table width="100%">
>          <tr>
>           <td align="right"
> width="{(count(ancestor-or-self::*) - 1) * 20}">
>           <xsl:choose>
>            <xsl:when test="child::tree_node">
>             <xsl:choose>
>              <xsl:when test="@id = $id or
> descendant::tree_node/@id = $id">
>               <xsl:choose>
>                <xsl:when test="@id = $id">
>                  <xsl:choose>
>                    <xsl:when test="$node = 'collapse'">
>                     <a href="{$url}&amp;id={@id}&amp;node=expand">
> <img border="0" width="16" height="16"
> src="images/ui_tree/book_close.gif"/>
>                    </a>
>                    </xsl:when>
>                    <xsl:otherwise>
>                     <a href="{$url}&amp;id={@id}&amp;node=collapse">
>  <img border="0" width="16" height="16"
> src="images/ui_tree/book_open.gif"/>
>                    </a>
>                    </xsl:otherwise>
>                  </xsl:choose>
>                </xsl:when>
>                <xsl:otherwise>
>                  <a href="{$url}&amp;id={@id}&amp;node=collapse">
> <img border="0" width="16" height="16"
> src="images/ui_tree/book_open.gif"/>
>                  </a>
>                </xsl:otherwise>
>              </xsl:choose>
>            </xsl:when>
>            <xsl:otherwise>
>              <a href="{$url}&amp;id={@id}&amp;node=expand">
> <img border="0" width="16" height="16"
> src="images/ui_tree/book_close.gif"/>
>              </a>
>            </xsl:otherwise>
>          </xsl:choose>
>        </xsl:when>
>       <xsl:otherwise>
> <img border="0" width="16" height="16"
> src="images/ui_tree/paper.gif"/>
>       </xsl:otherwise>
>     </xsl:choose>
>     </td>
>     <td>
>       <a href="{$url}&amp;page={@id}">
>         <xsl:value-of select="@value"/>
>       </a>
>     </td>
>     <td align="right" width="5%">
>       <a href="{$url}&amp;action=edit&amp;node={@id}">edit</a>
>     </td>
>     <td align="right" width="5%">
>       <a href="{$url}&amp;action=delete&amp;node={@id}"
> onClick="return
> deleteConfirm();">delete</a>
>     </td>
>   </tr>
> </table>
> </td>
> </tr>
> </xsl:template>
>
> Cheers,
>
> Adam
>
>
>
>
>
> Cheers,
> Adam
>  
> NB: "Pray as if everything depended upon God and work as if everything
> depended upon man."

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.