xslt - XSL XAML unique names -
i try make xaml file using xsl, , 1 of things need unique name 100 textblocks. create textblocks in for-each loop (which works, elements created) , try use position() give each unique name:
<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>
however, gives me this:
<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"/>
and on textblocks. note whitespace between "number_txt_" , digit.
i want use file in c# silverlight project, doesn't allow whitespaces in x:name, nor allow single digit (i've tried counter, doesn't work). have ideas? know of going suggest counter, knowledge small. thank you, taking time read problem, , hope can think of solution.
replace this:
<xsl:attribute name="x:name" select="'number_txt_',position()"/>
with:
<xsl:attribute name="x:name" select="concat('number_txt_',position())"/>
additionally, whole fragment:
<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>
can re-written in shorter , understandable form:
<textblock x:name="number_txt_{position()}" grid.row="{position()+2}" grid.column="0" text="{@number}" fontsize="20" foreground="ivory" horizontalalignment="center" verticalalignment="center">
Comments
Post a Comment