You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by de...@tcs.com on 2006/06/28 09:31:20 UTC

Urgent :break statement in xsl

Hi All,

        I am facing a problem in xsl.I am not sure whether it is possible 
in xsl or not.


        I have a <xsl:for-each> loop .I have a check condition in it.I 
want it to do something for the first time check condition is 
satisfied.After that it should not do anything.As i have a check condition 
in the loop i could not put [position=1] in the <xsl:for-each> loop.I 
tried with declaring a variable
and decreamenting its value if the check condition is satisfied.But it is 
not happening.

        Basically i want to break the <xsl:for-each>loop if one condition 
is satisfied.  Below is the code.


<xsl:variable name="daslcatagorypath" select="'/nos'"/>
 <xsl:for-each select="details/dasl:query-result/dasl:resource">
 
        <xsl:if test="d:resourcetype=''">
        <xsl:variable name="daslfolderpath"><xsl:value-of 
select="@dasl:path"/></xsl:variable>
        <xsl:variable name="check" 
select="substring-after($daslfolderpath,$daslcatagorypath)"/>
        <xsl:if test="$check!='' and $counter='1'">
                <xsl:variable name="size" select="d:getcontentlength"/>
                <xsl:variable name="kb-size" select="($size div 1000) - 
($size mod 1000 div 1000)"/>
                <xsl:value-of select="$kb-size"/><xsl:text> </xsl:text>KB
                <xsl:variable name="counter" select="'0'"/>
        </xsl:if>
        </xsl:if>
</xsl:for-each>


Can anyone suggest me the solution for it.
Thanks
Regards,
Deepak Kumar Sahoo
Tata Consultancy Services Limited
Mailto: deepakkumar.sahoo@tcs.com
Website: http://www.tcs.com
ForwardSourceID:NT0000922A 
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Re: Urgent :break statement in xsl

Posted by Lionel Barth <lb...@hachette-livre.fr>.
Hi,

May be you can use a xsl:choose + xsl:when instead of xsl:if :

<xsl:variable name="daslcatagorypath" select="'/nos'"/>
 <xsl:for-each select="details/dasl:query-result/dasl:resource">
         <xsl:choose>
                                                                        
     
        <xsl:when test="d:resourcetype=''">
        <xsl:variable name="daslfolderpath"><xsl:value-of 
select="@dasl:path"/></xsl:variable>
        <xsl:variable name="check" 
select="substring-after($daslfolderpath,$daslcatagorypath)"/>
        <xsl:if test="$check!='' and $counter='1'">
                <xsl:variable name="size" select="d:getcontentlength"/>
                <xsl:variable name="kb-size" select="($size div 1000) - 
($size mod 1000 div 1000)"/>
                <xsl:value-of select="$kb-size"/><xsl:text> </xsl:text>KB
                <xsl:variable name="counter" select="'0'"/>
        </xsl:if>
        </xsl:when>
        </xsl:choose>
</xsl:for-each>

In fact it does not break the loop but do nothing when the condition is 
not satisfied.

Regards,
Lionel

deepakkumar.sahoo@tcs.com a ecrit le 28/06/06 9:31:
>
>
>
> Hi All,
>
>         I am facing a problem in xsl.I am not sure whether it is 
> possible in xsl or not.
>
>
>         I have a <xsl:for-each> loop .I have a check condition in it.I 
> want it to do something for the first time check condition is 
> satisfied.After that it should not do anything.As i have a check 
> condition in the loop i could not put [position=1] in the 
> <xsl:for-each> loop.I tried with declaring a variable
> and decreamenting its value if the check condition is satisfied.But it 
> is not happening.
>
>         Basically i want to break the <xsl:for-each>loop if one 
> condition is satisfied.  Below is the code.
>
>
> <xsl:variable name="daslcatagorypath" select="'/nos'"/>
>  <xsl:for-each select="details/dasl:query-result/dasl:resource">
>                                                                       
>          
>         <xsl:if test="d:resourcetype=''">
>         <xsl:variable name="daslfolderpath"><xsl:value-of 
> select="@dasl:path"/></xsl:variable>
>         <xsl:variable name="check" 
> select="substring-after($daslfolderpath,$daslcatagorypath)"/>
>         <xsl:if test="$check!='' and $counter='1'">
>                 <xsl:variable name="size" select="d:getcontentlength"/>
>                 <xsl:variable name="kb-size" select="($size div 1000) 
> - ($size mod 1000 div 1000)"/>
>                 <xsl:value-of select="$kb-size"/><xsl:text> </xsl:text>KB
>                 <xsl:variable name="counter" select="'0'"/>
>         </xsl:if>
>         </xsl:if>
> </xsl:for-each>
>
>
> Can anyone suggest me the solution for it.
> Thanks
> Regards,
> Deepak Kumar Sahoo
> Tata Consultancy Services Limited
> Mailto: deepakkumar.sahoo@tcs.com
> Website: http://www.tcs.com
> ForwardSourceID:NT0000922A    
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Urgent :break statement in xsl

Posted by Geert Josten <ge...@daidalos.nl>.
Hi,

Your question is actually better of on the Mulberry XSL list, but
perhaps here something that will help you..

> <xsl:variable name="daslcatagorypath" select="'/nos'"/>  
> <xsl:for-each select="details/dasl:query-result/dasl:resource"> 
>                                                               
>                   
>         <xsl:if test="d:resourcetype=''"> 
>         <xsl:variable name="daslfolderpath"><xsl:value-of 
> select="@dasl:path"/></xsl:variable> 
>         <xsl:variable name="check" 
> select="substring-after($daslfolderpath,$daslcatagorypath)"/> 
>         <xsl:if test="$check!='' and $counter='1'"> 
>                 <xsl:variable name="size" 
> select="d:getcontentlength"/> 
>                 <xsl:variable name="kb-size" select="($size 
> div 1000) - ($size mod 1000 div 1000)"/> 
>                 <xsl:value-of select="$kb-size"/><xsl:text> 
> </xsl:text>KB 
>                 <xsl:variable name="counter" select="'0'"/> 
>         </xsl:if> 
>         </xsl:if>
> </xsl:for-each> 

If you are only interested in one occurrence of a list of nodes, why not
selecting just one, instead of looping over the list and triggering for
one case?

First of all, you can add the check statement into the select by putting
it in a predicate:

	select="details/dasl:query-result/dasl:resource"

Becomes:

	
select="details/dasl:query-result/dasl:resource[substring-after(@dasl:pa
th, $daslcatagorypath)]"

And if you are only interested in the first (in document order), put the
lot between braces and add [1] to the end:

	
select="(details/dasl:query-result/dasl:resource[substring-after(@dasl:p
ath, $daslcatagorypath)])[1]"

This expression always results in one node, ruling out the need for a
for-each. That should circumvent your problem..

Kind regards,
Geert
   
 
Drs. G.P.H. Josten
Consultant
 
 

Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org