XSL-XAML唯一名称
我尝试使用XSL创建一个XAML文件,我需要的一件事是为100个文本块提供一个唯一的名称。我在一个for each循环中创建文本块(这样做有效,所有元素都已创建),然后尝试使用position()为每个循环指定一个唯一的名称:XSL-XAML唯一名称,xaml,xslt,xslt-2.0,Xaml,Xslt,Xslt 2.0,我尝试使用XSL创建一个XAML文件,我需要的一件事是为100个文本块提供一个唯一的名称。我在一个for each循环中创建文本块(这样做有效,所有元素都已创建),然后尝试使用position()为每个循环指定一个唯一的名称: <xsl:for-each select="//value"> <xsl:element name="TextBlock"> <xsl:attribute name="x:Name" select="'number_txt_'
<xsl:for-each select="//value">
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
然而,这给了我这样的信息:
<TextBlock x:Name="number_txt_ 1" Grid.Row="3" Grid.Column="0" Text="1" FontSize="20"
Foreground="Ivory"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<TextBlock x:Name="number_txt_ 2" Grid.Row="4" Grid.Column="0" Text="2" FontSize="20"
Foreground="Ivory"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
对于所有文本块,依此类推。注意数字和数字之间的空白
我想在C#silverlight项目中使用此文件,但这不允许在x:Name中使用空格,也不允许使用单个数字(我只使用了计数器,但不起作用)。
有人有什么想法吗?我知道你们中的一些人会建议设立一个柜台,但我对此所知甚少。
感谢您抽出时间阅读我的问题,并希望您能想出一个解决方案。替换此问题:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
与:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
此外,整个片段:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
可以用更简短易懂的形式重新编写:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
替换此:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
与:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
此外,整个片段:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
可以用更简短易懂的形式重新编写:
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="x:Name" select="concat('number_txt_',position())"/>
<xsl:element name="TextBlock">
<xsl:attribute name="x:Name" select="'number_txt_',position()"/>
<xsl:attribute name="Grid.Row" select="position()+2"/>
<xsl:attribute name="Grid.Column" select="0"/>
<xsl:attribute name="Text" select="./@number"/>
<xsl:attribute name="FontSize" select="20"/>
<xsl:attribute name="Foreground" select="'Ivory'"/>
<xsl:attribute name="HorizontalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<xsl:attribute name="VerticalAlignment">
<xsl:value-of select="'Center'"/>
</xsl:attribute>
<TextBlock x:Name="number_txt_{position()}" Grid.Row="{position()+2}"
Grid.Column="0" Text="{@number}" FontSize="20" Foreground="Ivory"
HorizontalAlignment="Center" VerticalAlignment="Center">
工作起来很有魅力。非常感谢你!工作起来很有魅力。非常感谢你!