SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    elseif and returning code

    I have two questions is there any way to do a else if in xslt, and is there any way to do "functions" so that i dont have do write the same code more then ones here is an example from my one code:

    Code:
      
              <xsl:if test=&quot;$showPollId = 0&quot;> <!-- here i have i if -->
                 
                  <xsl:for-each select=&quot;/poll/showpoll&quot;>
         <!-- here i have a code that i want to have in a &quot;function&quot; -->
       <form method=&quot;post&quot; action=&quot;{$adress}?pollid={id}&showvotes=1&quot;>
       <table>
       <tr>
        <td>
       <td>
       <td>
        </tr>
        <xsl:for-each select=&quot;answer&quot;>
        <tr>
        <xsl:if test=&quot;$showPolls = 1&quot;>
        <td> 
        <td width='300'>[img]%22a.jpg%22[/img]
       <td>
       </xsl:if>
       <xsl:if test=&quot;$showPolls = 0&quot;>
       <td colspan='3'> 
        </xsl:if>
                 </tr>
       </xsl:for-each>
       <tr>
       <td colspan='3'>
        <xsl:if test=&quot;$pollAdmin = 1&quot;>
        <a href=&quot;{$adress}?removepollid={id}&quot;>ta bort
                 </xsl:if>
       <input type='submit' value='Rösta' name='B1'/>
       </tr> 
                </table>
        </form>
        <br/>
         <!-- here do function code ends -->
      </xsl:for-each>
         
                </xsl:if><!-- here i dont want to close the &quot;if&quot;, i want a else if instead -->
                
                <xsl:if test=&quot;$showPollId != 0&quot;>
                
        <xsl:for-each select=&quot;/poll/showpoll[id=$showPollId]&quot;>
         <!-- here i have a code that i want to have in a &quot;function&quot; again  -->
        <form method=&quot;post&quot; action=&quot;{$adress}?pollid={id}&showvotes=1&quot;>
        <table>
       <tr>
       <td>
                 <td>
        <td>
       </tr>
        <xsl:for-each select=&quot;answer&quot;>
        <tr>
       <xsl:if test=&quot;$showPolls = 1&quot;>
        <td> 
       <td width='300'>[img]%22a.jpg%22[/img]
        <td>
            </xsl:if>
        <xsl:if test=&quot;$showPolls = 0&quot;>
       <td colspan='3'> 
       </xsl:if>
       </tr>
        </xsl:for-each>
       <tr>
       <td colspan='3'>
        <xsl:if test=&quot;$pollAdmin = 1&quot;>
        <a href=&quot;{$adress}?removepollid={id}&quot;>ta bort
                
        </xsl:if>
       <input type='submit' value='Rösta' name='B1'/>
       </tr>
                
        </table>
        </form>
        <br/>
         <!-- here do function code ends -->
      </xsl:for-each>
                </xsl:if>

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use xsl:templates to do just that.

    As for the elseif, you have to use xsl:choose.
    Code:
     <xsl:choose>
        <xsl:when test="condition1">
     	  condition 1 stuff
        </xsl:when>
        <xsl:when test="condition2">
     	  condition 2 stuff
        </xsl:when>
        <xsl:otherwise>
     	  this is an else statement
        </xsl:otherwise>
     </xsl:choose>

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx, but i do not understand how two use xsl:templates

    <xsl:apply-templates select="what"/>

    and

    <xsl:template match="/what" >

    cause i want to iterate trove
    <xsl:for-each select="/poll/showpoll">
    here i want to call to <xsl:template match="/poll/showpoll">
    and get access to all under nodes, but i don’t understand how to do it, my xml file looks like this:


    Code:
    <poll>
        	<showpoll> 
        		<id>1
        		<question>fungera
        		<running>1
        		<totalVotes>2
        		<answer> 
        			<id>0
        			<name>Ja
        			<votes>1
        			<width>150
        		</answer> 
        		<answer> 
        			<id>1
        			<name>Nej
        			<votes>1
        			<width>150
        		</answer> 
        		<answer> 
        			<id>2
        			<name>osv
        			<votes>0
        			<width>1
        		</answer> 
        	</showpoll> 
        	<showpoll> 
        		<id>2
        		<question>hoppas
        		<running>1
        		<totalVotes>8
        		<answer> 
        			<id>0
        			<name>Ja
        			<votes>0
        			<width>1
        		</answer> 
        		<answer> 
        			<id>1
        			<name>Nej
        			<votes>2
        			<width>75
        		</answer> 
        		<answer> 
        			<id>2
        			<name>osv
        			<votes>6
        			<width>225
        		</answer> 
        	</showpoll> 
        </poll>
    Last edited by durus; May 3, 2005 at 11:42. Reason: spelling

  4. #4
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to close all of your tags (id, name, votes, width specifically) before you can do anything with it.

  5. #5
    SitePoint Member
    Join Date
    May 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there closed somthing went wrong when i posted them here


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •