Groups > Design > Microsoft xsl > Re: Help? - xsl if statement




Re: Help? - xsl if statement

Re: Help? - xsl if statement
Sun, 13 Apr 2008 08:50:55 +010
"Julie Smith" <julie@home.com> wrote in message
news:%23DxAu7RnIHA.3940@TK2MSFTNGP05.phx.gbl...
> Hi,
> I want to do this:
> <xsl:if test="true"></tr></xsl:if>
>
> However, I keep getting an error about the </tr>. How can i do this?
>


Since XSL is XML it needs to be well formed.  You can't therefore end an
element conditionally in the way above.  Can you provide more detail of the
problem you want to solve?


-- 
Anthony Jones - MVP ASP/ASP.NET

Post Reply
Re: Help? - xsl if statement
Sun, 13 Apr 2008 13:27:54 +020
Julie Smith wrote:
> I'm trying to iterate through a collection and list them in a table 
> going horizontally, not vertically.
> Example of what i've currently got, but not working:
> 
> <xsl:variable name="columns" select="5"/>
> <table>
> <xsl:for-each select="//People">
>  <xsl:if test="(position() mod $columns) =
0"><tr></xsl:if>
>   <td>
>    <xsl:value-of select="@name"/>
>   </td>
>  <xsl:if test="(position() mod $columns) =
0"></tr></xsl:if>
> </xsl:for-each>
> </table>


You need to use a different approach, like this:
  <table>
   <xsl:for-each select="//People[position() mod $columns =
0]">
     <tr>
       <xsl:for-each select=". | following-sibling::People[position() 
&lt; $colums]">
         <td>
           <xsl:value-of select="@name"/>
         </td>
       </xsl:for-each>
     </tr>
   </xsl:for-each>
  </table>

-- 

	Martin Honnen --- MVP XML
Post Reply
Help? - xsl if statement
Sun, 13 Apr 2008 14:29:11 +100
Hi,
I want to do this:
<xsl:if test="true"></tr></xsl:if>

However, I keep getting an error about the </tr>. How can i do this?

Post Reply
Re: Help? - xsl if statement
Sun, 13 Apr 2008 18:55:20 +100
I'm trying to iterate through a collection and list them in a table going 
horizontally, not vertically.
Example of what i've currently got, but not working:

<xsl:variable name="columns" select="5"/>
<table>
 <xsl:for-each select="//People">
  <xsl:if test="(position() mod $columns) =
0"><tr></xsl:if>
   <td>
    <xsl:value-of select="@name"/>
   </td>
  <xsl:if test="(position() mod $columns) =
0"></tr></xsl:if>
 </xsl:for-each>
</table>

Does that make sense?


"Anthony Jones" <Ant@yadayadayada.com> wrote in message 
news:uJQEcsTnIHA.4372@TK2MSFTNGP05.phx.gbl...
>
> "Julie Smith" <julie@home.com> wrote in message
> news:%23DxAu7RnIHA.3940@TK2MSFTNGP05.phx.gbl...
>> Hi,
>> I want to do this:
>> <xsl:if test="true"></tr></xsl:if>
>>
>> However, I keep getting an error about the </tr>. How can i do
this?
>>
>
>
> Since XSL is XML it needs to be well formed.  You can't therefore end an
> element conditionally in the way above.  Can you provide more detail of 
> the
> problem you want to solve?
>
>
> -- 
> Anthony Jones - MVP ASP/ASP.NET
>
> 
Post Reply
Re: Help? - xsl if statement
Mon, 14 Apr 2008 13:10:54 +020
Julie Smith wrote:
> Thank you soooo much! I go it to work. But i have another question. What 
> if i have a second level in the xml data? As in, //Animals/People? I
tried:
> select="//Animals/People[position() mod $columns = 0]">
> 
> But that didn't work. Any ideas?

Provide a meaningful sample of your XML input document and tell us 
exactly what does not work. Do you get an error? Or do you simply not 
get the result you want? Which result exactly do you expect? And which 
result do you get?

-- 

	Martin Honnen --- MVP XML
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact