is any way to transform TreeView from XAML to XSLT using for loop or any other condition without hard coding.

Hi,

I want to know how to transform TreeView from XAML to XSLT using for loop or any other condition without hard coding.

I tried for some things

My XAML code is

<TreeView Tag="se1" Foreground="Black" Canvas.Top="450" Width="100" FontSize="15" Canvas.Left="500" >

<TreeViewItem Tag="se4" Header=" Points paid for this loan" IsExpanded="False" >

<TreeViewItem IsExpanded="False" Tag="se2" Header="Check if points were paid this year">

<TreeViewItem Tag="se3" Header="Points paid in 2004 are either for a new home or refinancing an"/>

</TreeViewItem>

<TreeViewItem Tag="se2" Header="Check if points were paid in a previous year"/>

</TreeViewItem>

<TreeViewItem IsExpanded="False" Tag="se4" Header="Jeevan" >

<TreeViewItem IsExpanded="False" Tag="se2" Header="Jeevan1"/>

<TreeViewItem IsExpanded="False" Tag="se2" Header="Jeevan2"/>

</TreeViewItem>

</TreeView>

My XSLT is

<xsl:template match="TreeView" >

<xsl:variable name="m" select="@Foreground"/>

<asp:TreeView Runat="server" ForeColor="{$m}">

<xsl:for-each select="TreeViewItem " >

<Nodes>

<xsl:if test="@Tag='se4'">

<xsl:variable name="y" select="@IsExpanded"/>

<xsl:variable name="My" select="@Header"/>

<asp:TreeNode Runat="server" Text="{$My}" Expanded="{$y}" >

<xsl:for-each select="TreeViewItem " >

<xsl:if test="@Tag='se2'">

<xsl:variable name="M" select="@Header"/>

<asp:TreeNode Runat="server" Text="{$M}" >

<xsl:for-each select="TreeViewItem " >

<xsl:if test="@Tag='se3'">

<xsl:variable name="M2" select="@Header"/>

<asp:TreeNode Runat="server" Text="{$M2}" >

</asp:TreeNode>

</xsl:if>

</xsl:for-each>

</asp:TreeNode>

</xsl:if>

</xsl:for-each>

</asp:TreeNode >

</xsl:if>

</Nodes>

</xsl:for-each>

</asp:TreeView>

</xsl:template>

Can u tell me how to transform without hard coding

Thanks,

Gomathi




Answer this question

is any way to transform TreeView from XAML to XSLT using for loop or any other condition without hard coding.

  • vcooking

    if you are talking about this line:

    <xsl:if test="@Tag='se2'">

    Then the way this is normally done is you turn this into a "parameter" to the stylesheet as follows:

    <xsl:if test="@Tag='$tag'">

    and add this to the top of your stylesheet:

    <xsl:param name="tag"/>

    Then pass this parameter to the XslTransform at runtime.

    If you want to pass any XPath expression here, rather than just the @Tag attribute value, then this requires XmlDocument manipulation since XSLT does not support dynamic select.

    So you load the XSLT into an XmlDocument, find the <xsl:if test="@Tag='$tag'"> element using SelectSingleNode, then set the test attribute value, then you load the XslTransform using this XmlDocument. The downside to this approach is if you are using XmlCompiledTransform you will need to recompile the transform each time you change the XmlDocument - so you might want to consider how much caching of commonly used queries you can do here for better scalability.


  • Arthg2000

    It seems that you translate XAML to ASP (not to XSLT).

    The only way to do this without hard coding is find somebody’s XSLT or other program that does this.

    What’s wrong with your own code



  • is any way to transform TreeView from XAML to XSLT using for loop or any other condition without hard coding.