xsl-list
[Top] [All Lists]

Re: XSL Queries

2006-02-13 04:41:08

Personally, I dislike "if-then" without an "else" clause & prefer an "else" with an explicit "do nothing" statement,
i.e. Rule: all execution paths should be explicit



Also , the reason why If statement is there in the first instance is to imply that there is no "else".

an if-then-else is catered for using the xsl:choose.

So your rule,
i.e. Rule: all execution paths should be explicit
still holds good even if you use <xsl:if>. as xsl:if explicitly says that "this test doesnt have an alternate option"

as in XSLt Spec : "There are two instructions in XSLT that support conditional processing in a template: xsl:if and xsl:choose. The xsl:if instruction provides simple if-then conditionality; the xsl:choose instruction supports selection of one choice when there are several possibilities."

So i think using one of these two instructions , you are making your intentions clear anyway. Although It is a good idea to use choose when you are not sure if there will be more options..still it is easy to change to "Choose" from "If" - If the business changes.

Also .. Choose statement is more bulkier than an if statement. and an if statement is short form of a choose with empty otherwise. and for an experienced eye, it will look odd.

Vasu





From: Andrew Franz <afranz0(_at_)optushome(_dot_)com(_dot_)au>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XSL Queries
Date: Mon, 13 Feb 2006 21:52:40 +1100

Vasu Chakkera wrote:

:-)
except

   <xsl:choose>
   <xsl:when test="($basics &gt;= 'understood')">
       <xsl:message terminate = "yes">Feel free to ask</xsl:message>
   </xsl:when>
   </xsl:choose>



could have been

<xsl:if test="($basics &gt;= 'understood')">
      <xsl:message terminate = "yes">Feel free to ask</xsl:message>
   </xsl:if >

with just a single test case...


Thanks, Vasu - it just shows that we all have something to learn.

Personally, I dislike "if-then" without an "else" clause & prefer an "else" with an explicit "do nothing" statement,
i.e. Rule: all execution paths should be explicit

Mapping this into the above, I should have included an <xsl:otherwise>


<xsl:with-param name="effort">basics</xsl:with-param>
is better with
<xsl:with-param name="effort" select = "'basics'"/>


Manoj..
Its true what andrew said.. you must learn atleast some basics or look into faqs or do some work before jumping into the lists...
anyway as you have asked, i shall give u some inputs ...

use a xsl:for-each select = "catagory" to loop through the catagories and use <xsl:value-of select = "@type"/> to print the types. This is all XSL can do for you. clicking the link and displaying the price is not its job.. you can possibly use javascript for this.

this might work for you


lemme do the whole thing for you. I think i have some free time.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:template match="orders">
        <script type="text/javascript">

            function myfunction (price)
            {
// 1. get the div with id = "showprice".. this is where the price will show up

var showprice = document.getElementById ( "showprice")

//2. get the div with id = "price".. this is the div that has the price value // this div is set to invisible mode by style= display:none

                    var priceVal     = document.getElementById(price)

                // Setting the showprice div with the price value
                      showprice.innerHTML = priceVal.innerText;
            }
        </script>
        <table border="1">
            <tr>
                <th>catagory</th>
                <th>price</th>
            </tr>
            <tr>
                <td >
                    <xsl:for-each select="category">
                        <div id = "{(_at_)type}">
                            <a onclick="myfunction({price})" href = "#">
                                <xsl:value-of select="@type"/>
                            </a>
                        </div>
                        <hr/>
                        <div id = "{price}" style="display:none">
                            <xsl:value-of select="price"/>
                        </div>
                    </xsl:for-each>
                </td>
                <td>
                    <div id = "showprice"></div>
                </td>
            </tr>
        </table>
    </xsl:template>
</xsl:stylesheet>

HTH
Vasu

From: Andrew Franz <afranz0(_at_)optushome(_dot_)com(_dot_)au>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XSL Queries
Date: Sat, 11 Feb 2006 16:52:05 +1100

Easy.

This should solve your problem:

<xsl:template match="bookstore">
<xsl:apply-templates select="book[(@author='Kay') or (@author='Tennyson')]" />
   <xsl:call-template name="diy" />
   <xsl:choose>
   <xsl:when test="($basics &gt;= 'understood')">
       <xsl:message terminate = "yes">Feel free to ask</xsl:message>
   </xsl:when>
   </xsl:choose>
</xsl:template>

<xsl:template match="book">
   <xsl:call-template name="read">
       <xsl:with-param name="effort">basics</xsl:with-param>
   </xsl:call-template>
</xsl:template>


manoj kumar wrote:

Hi everyone,

    I have an xml file with details
<orders>
<category type='shirt'>
<price>100</price>
</category>
<category type='Tshirt'>
<price>150</price>
</category>
<category type='Jeans'>
<price>500</price>
</category>
<category type='Pant'>
<price>750</price>
</category>
</orders>

In an xsl file i have to list type of categories in left side on clicking= particular tag the price details should be displayed on right. Give me a =
sample of this, so that i can develop  it further [

EX: click link pant should display 750 on right hand side

Please send to this email-ID :b_manoj(_at_)india(_dot_)com

Thanks in Advance,
Manoj







--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 7.5 today! http://messenger.msn.co.uk


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>