generate html from XSLT in c#

Posted by RohiK under XML on 12/14/2010 | Points: 10 | Views : 10047 | Status : [Member] | Replies : 3
hi all,

I want to create html form xslt and passing xml file to it.
but I don't understand how to to execute/ display html from that xslt.

is there any namspace have to add ?

how to do that?


plz help

Happy Programming!!
Rohi



Responses

Posted by: SheoNarayan on: 12/14/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
This article should help you http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=63

Thanks!

Regards,
Sheo Narayan
http://www.dotnetfunda.com

RohiK, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 12/14/2010 [Member] Starter | Points: 25

Up
0
Down
hi ,

I want to create aspx controls like Gridview from xslt is it possible..?

I am just now trying , I have xml like


<Control>

<ControlName>GridView</ControlName>
<Property>
<PropertyName>ID</PropertyName>
<ValueCollection>
<value attribute="default">"grd"</value>
</ValueCollection>
</Property>
<Property>
<PropertyName>runat</PropertyName>
<ValueCollection>
<value attribute="default">"server"</value>
</ValueCollection>
</Property>
<Columns>
<TemplateField>
<Property>
<PropertyName>HeaderText</PropertyName>
<ValueCollection>
<value attribute="default">"$HeaderText"</value>
</ValueCollection>
</Property>
<ItemTemplate>
</ItemTemplate>
</TemplateField>
</Columns>
</Control>


and I want to create gridview like

<asp:GridView Id=".....></asp:GridView>


how to write xslt...?

Happy Programming!!
Rohi

RohiK, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 12/14/2010 [Member] Starter | Points: 25

Up
0
Down
hiiii,

I have searched and found it.

I am giving my xslt file here if anybody need it ,


<
?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:asp="remove">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<asp:GridView runat="server">
<xsl:attribute name="ID">
<xsl:text >grd</xsl:text>
<xsl:value-of select ="table/TableName"/>
</xsl:attribute>
<xsl:for-each select ="table/Columns">
<xsl:for-each select="child::*">
<xsl:variable name="ColumnN">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:variable name="DataType">
<xsl:value-of select="@dataType"/>
</xsl:variable>
<xsl:variable name="isPK">
<xsl:value-of select="@isPrimaryKey"/>
</xsl:variable>
<xsl:variable name="isFK">
<xsl:value-of select="@isForeignKey"/>
</xsl:variable>
<xsl:if test ="$isPK='false' and $DataType!='date'">
<asp:TemplateField HeaderText="{$ColumnN}">
<ItemTemplate>
<xsl:text>'&lt;#%Eval(</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>)%&gt;' </xsl:text>
</ItemTemplate>
</asp:TemplateField>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</asp:GridView>
</xsl:template>
</xsl:stylesheet>


here first I have created an xml document of my table(any table)
this is look like

<
?xml version="1.0"?>

<table>
<TableName>AdminLogin</TableName>
<Columns>
<ColumnName name="UserName" dataType="varchar" IsNull="NO" length="50" isPrimaryKey="false" isForeignKey="false" />
<ColumnName name="Password" dataType="varchar" IsNull="NO" length="50" isPrimaryKey="false" isForeignKey="false" />
<ColumnName name="CreatedOn" dataType="date" IsNull="NO" length="" isPrimaryKey="false" isForeignKey="false" />
<ColumnName name="Id" dataType="int" IsNull="NO" length="" isPrimaryKey="true" isForeignKey="false" />
</Columns>
</table>


and generating normal aspx from tranforming that xslt
in cs I wrote
XslFile = @"XSLT\GridView.xslt";

xdoc = gn.GenerateTableSchema(drpTable.SelectedValue.ToString());
XsltArgumentList xslarg = new XsltArgumentList();
XslTransform xsl = new XslTransform();
xsl.Load(XslFile);
StringWriter sw = new StringWriter();
xsl.Transform(xdoc, xslarg, sw);
string result = sw.ToString().Replace("xmlns:asp=\"remove\"",
"").Replace("&lt;", "<").Replace("&gt;", ">");
// free up the memory of objects that are not used anymore
string result1 = sw.ToString().Replace("xmlns:asp=\"remove\"",
"").Replace("&lt;", "<").Replace("&gt;", ">");
sw.Close();
txtAns.Text = result1;


just run it ... in txtAns textbox displays gridview control.

try it and generate many controls.



Happy Programming!!
Rohi

RohiK, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response