开发者

Xsl & Silverlight: Using XSLT and an algorithm, how do I print out the entire Latin alphabet (a,b,c..z)?

I would like to have this:

Using XSLT, put each letter of th开发者_运维技巧e alphabet in its own grid cell. The end result will be (result.xaml):

XAML Grid: 1 column, 26 rows. One row for each letter of the alphabet.

Perhaps there is an ASCII code way of doing this? I am not sure.

Thanks


The recursive template printAlphabetRows in the following stylesheet iterates from 1 to 26 and uses xsl:number with the format option to print the corresponding letter in each iteration.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/">

      <Grid xmlns="http://schemas.microsoft.com/winfx/avalon/2005" Width="400" Height="200"
            Background="LightBlue"> 
         <ColumnDefinition/>
         <RowDefinition Height="Auto"/>
         <xsl:call-template name="printAlphabetRows"/>
      </Grid>
   </xsl:template>

   <xsl:template name="printAlphabetRows">
      <xsl:param name="letter" select="1"/>

      <TextBlock Grid.Column="0" Grid.Row="0">
         <xsl:number value="$letter" format="a"/>
      </TextBlock>

      <xsl:if test="$letter &lt; 26">
         <xsl:call-template name="printAlphabetRows">
            <xsl:with-param name="letter" select="$letter+1"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>
</xsl:stylesheet>

Note: I don't know anything about XAML Grids, so that XML structure may be off slightly (I googled for examples of XAML Grid), but it should be enough to see how the template could be used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜