2

Is there a way to display a C# control through XSLT?

I'm trying a lot to handle this but am not able to pass the values to the control.

Below is the sample which am trying to render it out..

<xsl:text disable-output-escaping="yes">&lt;Control:Content runat="server" contenttype="&lt;xsl:value-of select="subnode/text()"/&gt;" /&gt;</xsl:text>

Here control should generate as shown: For the param "contenttype" value should pass dynamically...

<Control:Content runat="server" contenttype="ABC123" />

Please help me.

2
  • Good question, +1. Remember that DOE is almost never necessary and should be avoided whenever possible, as it breaks the XSLT architectural model. Commented Sep 12, 2011 at 12:40
  • What are you going to do with the result of the transformation? Commented Sep 12, 2011 at 12:56

2 Answers 2

2

You don't need (and it is always a good idea to avoid using) DOE for this.

Here is a neat solution, just using <xsl:output method="text">:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/*">
  <xsl:text>&lt;Control:Content runat="server" contenttype="</xsl:text>
  <xsl:value-of select="/subnode"/>
  <xsl:text>" /&gt;</xsl:text>
 </xsl:template>
</xsl:stylesheet>

when this transformation is applied on this XML document:

<subnode>html</subnode>

the wanted, correct output is produced:

<Control:Content runat="server" contenttype="html" />
Sign up to request clarification or add additional context in comments.

1 Comment

Thats great Dimitre.. Works as expected.
1

We're using this technique at work, however, we convert the control to xml first then we use xslt to render it in the page.

1 Comment

Thanks for the reply. In my scenario, it won't works this way. Since content is already published to XML & this can't be handled at this point. So while XML is rendering then i should handle that by passing the value to the control & display on the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.