Page 1 of 3

[Solved] if length and 0 displays link

Posted: Fri Nov 24, 2017 1:40 pm
by Alex Ivanovich
how to solve this?

if the length (hours-minutes-seconds) and 0 displays the link :roll:

this code does not work :|

code to add

Code: Select all

			  
			  <xsl:choose>
			  <xsl:when test="length='0'">
			  
			  <xsl:text> | </xsl:text>
			  <a href="http://___.com/">go url</a>
			  </xsl:when>
			   </xsl:choose
			  
original code

Code: Select all

<tr>            
            <td class="record_pane_table_fieldname" nowrap=""><xsl:value-of select="/data/fld/video/length/@name"/></td>
            <td class="record_pane_table_fieldvalue">
              <xsl:if test="length/@hours>0">
                <xsl:value-of select="length/@hours"/><xsl:text> ore </xsl:text>
              </xsl:if>
              <xsl:value-of select="length/@minutes"/><xsl:text> minuti </xsl:text>
              <xsl:if test="length/@seconds>0">
                <xsl:value-of select="length/@seconds"/><xsl:text> secondi </xsl:text>
              </xsl:if>
			  </td>
          </tr>

Re: if length and 0 displays link

Posted: Sat Nov 25, 2017 6:31 am
by LotsOCds
Alex,

Always look at the XML. Here you will find the answer.

Code: Select all

<length hours="0" minutes="0" seconds="0">0:00</length>
So you need to write:

Code: Select all

<xsl:when test="length='0:00'">

Re: if length and 0 displays link

Posted: Sat Nov 25, 2017 7:28 am
by Alex Ivanovich
Hi Dave, :)

does not work :| :roll:

Code: Select all

<tr>            
            <td class="record_pane_table_fieldname" nowrap=""><xsl:value-of select="/data/fld/video/length/@name"/></td>
            <td class="record_pane_table_fieldvalue">
			<xsl:if test="length/@hours>0"> 
                <xsl:value-of select="length/@hours"/>
				
	   <xsl:choose>
           <xsl:when test="length='0:00'">
          <xsl:text> | </xsl:text>
			  <a href="http://akas.imdb.com/find?q={title}">IMDB</a>
           </xsl:when>
            </xsl:choose>
				
		<xsl:choose><!-- se la lunghezza delle ore ha valore 1 (uno) allora sostituisce ore con ora -->
            <xsl:when test="length/@hours> 1">
              ore
            </xsl:when>
            <xsl:otherwise>
              ora
            </xsl:otherwise>
         </xsl:choose> <!-- se la lunghezza delle ore ha valore 1 (uno) allora sostituisce ore con ora -->
		 </xsl:if>
              <xsl:value-of select="length/@minutes"/><xsl:text> minuti </xsl:text>
              <xsl:if test="length/@seconds>0">
                <xsl:value-of select="length/@seconds"/><xsl:text> secondi </xsl:text>
				
				</xsl:if>
			  </td>
          </tr>

Re: if length and 0 displays link

Posted: Sat Nov 25, 2017 9:55 pm
by LotsOCds
Alex Ivanovich wrote:does not work :| :roll:
Sure it does! The problem now is with the logic in your code. Can you spot the problem?

Here's an abbreviated version of your code that should make the logic problem clear.

Code: Select all

<xsl:if test="length/@hours>0"> 
...
    <xsl:choose>
      <xsl:when test="length='0:00'">
      </xsl:when>
    </xsl:choose>
...    
</xsl:if>
        

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 12:21 am
by Alex Ivanovich
This work in half
view the link
minutes
but it does not show the hours :|

Code: Select all

xsl:if test="length/@hours='0'">
          <tr>            
            <td class="record_pane_table_fieldname" nowrap=""><xsl:value-of select="/data/fld/video/length/@name"/></td>
            <td class="record_pane_table_fieldvalue">
          
                <xsl:value-of select="length"/>
             <xsl:choose>
               <xsl:when test="length='0:00'">
	            inserire la durata
				<a href="http://akas.imdb.com/find?q={title}">IMDB</a>
	           </xsl:when>
             </xsl:choose>
            </td>
          </tr>
      </xsl:if>           
             
             
(then I translate it into Italian)
this should change the text as well
example: (hours, minutes, seconds)
1:40:30
result
1 hour 40 minutes and 30 seconds

example (hour)
1:00:30
result
1 hour and 30 seconds

example (minutes)
00:40
result
40 minutes

example (hour and hours, plural)
1:00 hour
2:00 hours

example (minute and minute)
1 minute
10 minutes

the code does not work :|

Code: Select all

<xsl:if test="length/@hours > 0"> <!-- se la lunghezza delle ore ha valore 0 (zero) allora non visualizzare -->
	  <xsl:value-of select="length/@hours"/>
	  <xsl:choose>
            <xsl:when test="length/@hours> 1"><!-- se la lunghezza delle ore ha valore 1 (uno) allora sostituisce ore con ora -->
              ore
            </xsl:when>
            <xsl:otherwise>
              ora
            </xsl:otherwise>
         </xsl:choose>
	  </xsl:if>
	<xsl:text> minuti </xsl:text>
	  <xsl:if test="length/@seconds > 0"> <!-- se la lunghezza dei secondi ha valore 0 (zero) allora non visualizzare -->
	  <xsl:text> e </xsl:text>
	  <xsl:text> secondi </xsl:text>
	  </xsl:if>

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 3:42 pm
by LotsOCds
Alex Ivanovich wrote:This work in half
view the link
minutes
but it does not show the hours :|
Look at the XML! Example:

Code: Select all

<length hours="0" minutes="30" seconds="22">30:22</length>
the code does not work
I don't understand. The code does not look complete. There is no code to show minutes or seconds.

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 4:13 pm
by Alex Ivanovich
:roll: :| :roll: I don't understand

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 4:23 pm
by LotsOCds
Alex Ivanovich wrote::roll: :| :roll: I don't understand
Please be more specific.

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 4:35 pm
by Alex Ivanovich
LotsOCds wrote:
Alex Ivanovich wrote:This work in half
view the link
minutes
but it does not show the hours :|
Look at the XML! Example:

Code: Select all

<length hours="0" minutes="30" seconds="22">30:22</length>
:| :roll: :|

Re: if length and 0 displays link

Posted: Sun Nov 26, 2017 5:17 pm
by LotsOCds
There are no hours in the XML representation "30:22"

Remember your code tests for length/@hours='0' so no hours will be shown by <xsl:value-of select="length"/>