Answered by:
How assign the value to a attribute dynamicaally ?

Question
-
User213108198 posted
hi,
I hav code
<xsl:for-each select="Exclusion">
<span>
<input type="text">
<xsl:attribute name="name"><xsl:value-of select="../@table" />[<xsl:value-of select="../@column" />][]</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
<xsl:attribute name="defaultValue"></xsl:attribute>
</input>
<a href="#" onclick="this.parentNode.innerHTML='';return false;">Remove</a>
<br/>
</span>
</xsl:for-each>I want to assign the value to defaultValue dynamicaaly like how the value field is assigning .so lz help me .my c# code is..
XmlNode Main = xDoc.SelectSingleNode("//Exclusion1");
XmlNode aNewNode = xDoc.CreateNode(XmlNodeType.Element, "Exclusion", "");
aNewNode.InnerText = aSection.Content;aeNode.AppendChild(aNewNode);
Here i want to assign the same row value to default field....plz help me ...
Wednesday, January 8, 2014 5:39 AM
Answers
-
User-933407369 posted
XmlNode Main = xDoc.SelectSingleNode("//Exclusion1"); XmlNode aNewNode = xDoc.CreateNode(XmlNodeType.Element, "Exclusion", ""); aNewNode.InnerText = aSection.Content; aeNode.AppendChild(aNewNode);
sorry, i don't give you the exact code, because of your code which is not working for me.
i think that you need to add <xsl:param> tag, and you also need to use the param in <xsl:attribute>. if you do it, you only need to create the code below:
XsltArgumentList xslArgs = new XsltArgumentList(); xslArgs.AddParam("logo", "", logo); xslArgs.AddParam("name", "", name);
In the stylesheet, parameters are defined as follows
<xsl:param name="logo"/> <xsl:param name="name"/>
since the param get the new value, the <xsl:attribute>also has the same value.
Please refer to the links below and check out the complete codes:
http://www.codeproject.com/Articles/8574/Generate-dynamic-ASP-NET-pages-by-using-XML-and-XS
http://www.codeproject.com/Articles/87621/Introduction-to-XML-and-XSLT-in-Csharp-NET
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 17, 2014 7:11 AM
All replies
-
User-1599577208 posted
Looking at your XML it is seen that the XML is having the same attribute so either you can find the name attr placed at 3 location.
xmlNode.Attributes[attributeName].InnerText
But it will fail in case the default value comes at 4th location or any other location.
For this Particualar reason you can place ##DefaultValue##
<xsl:attribute name="##DefaultValue##"></xsl:attribute>
And later you can replace the XMLString with the required value
XMLString.Replace("##DefaultValue##","Required Value");
Hope I was able to solve your query.
Sagar Shete (MCTS)
Wednesday, January 8, 2014 6:44 AM -
User213108198 posted
hi,
where is the same atribute yaar
i asked u how to add value to that defaultvalue through c# code dynamically from database ?????
like
<input name="posting[exclusion_criteria][]" type="text" defaultValue="" value="Subjects with pending Worker"/>
here value atribute has value right so i need that defaultvalue atrribute value or i want to assign through code ..how it is possible???????????how to get that attribute in c# code .then only i can assign right...
Wednesday, January 8, 2014 7:48 AM -
User-933407369 posted
hi Prava29,
Declares a named parameter for use within an <xsl:stylesheet>element or an <xsl:template>
element. Allows specification of a default value.
http://msdn.microsoft.com/en-us/library/ms256096(v=vs.110).aspx
Please to refer to the link below:
Passing parameters to XSLT Stylesheet via .NET
problem in passing parameter <xsl:for each
Hope they can help you.
Friday, January 10, 2014 4:45 AM -
User213108198 posted
hi
I just want t add the value to the differenet atribute of the same textbox.I dnt need any parameter just help me .How i show that in value field it is adding thae value.
Friday, January 10, 2014 5:00 AM -
User-933407369 posted
hi,
i would suggest you try to use template and use select to match the items, as shown below:
<xsl:template match="item-descriptor[@name='product']"> <product> <xsl:apply-templates select="*/@name[not(starts-with(.,'attr'))]"/> <attributes> <xsl:apply-templates select="*/@name[starts-with(.,'attr')]"/> </attributes> </product> </xsl:template>
please refer to the link below for details:
Transforming XML using XSLT
http://stackoverflow.com/questions/3945054/transforming-xml-using-xslt
Hope it helps you.
Monday, January 13, 2014 4:30 AM -
User213108198 posted
Sorry i cant able to do like this just tell me the code what to write in c# according my requirement plzzz.
Wednesday, January 15, 2014 8:49 AM -
User-227760790 posted
please refer to the link below:
XSLT Transformations with the XslTransform Class
http://msdn.microsoft.com/en-us/Library/ts9by56w(v=vs.100).aspx
Calling a .NET C# class from XSLT
Minimalist XSLT Transform Using Two Strings
Thursday, January 16, 2014 6:31 AM -
User213108198 posted
Thanks for giving this but i am totally new on xslt and xml can u plz told me exact code what will be for my c# code ...plz,....
Thursday, January 16, 2014 6:45 AM -
User-933407369 posted
XmlNode Main = xDoc.SelectSingleNode("//Exclusion1"); XmlNode aNewNode = xDoc.CreateNode(XmlNodeType.Element, "Exclusion", ""); aNewNode.InnerText = aSection.Content; aeNode.AppendChild(aNewNode);
sorry, i don't give you the exact code, because of your code which is not working for me.
i think that you need to add <xsl:param> tag, and you also need to use the param in <xsl:attribute>. if you do it, you only need to create the code below:
XsltArgumentList xslArgs = new XsltArgumentList(); xslArgs.AddParam("logo", "", logo); xslArgs.AddParam("name", "", name);
In the stylesheet, parameters are defined as follows
<xsl:param name="logo"/> <xsl:param name="name"/>
since the param get the new value, the <xsl:attribute>also has the same value.
Please refer to the links below and check out the complete codes:
http://www.codeproject.com/Articles/8574/Generate-dynamic-ASP-NET-pages-by-using-XML-and-XS
http://www.codeproject.com/Articles/87621/Introduction-to-XML-and-XSLT-in-Csharp-NET
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 17, 2014 7:11 AM