How can I render custom XSL controls in my XSLT file with C#?
I'm using C# to translate a XML file to HTML with the use of XSLT.
I use an Extension object to render my own code:
<?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:widget="urn:serverTime"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="demo:printTime()"/>
</xsl:开发者_如何学Ctemplate>
and in my C#:
XsltArgumentList myList = new XsltArgumentList();
myList.AddExtensionObject("demo:serverTime", new ServerTime());
transform.Transform(document, myList, writer);
This works perfectly. However, I would like to create my own custom tags like:
<demo:printTime />
This doesn't work: the tag is printed to the output without being rendered. How can I make this work so I can use my own tags?
You can't do this. XSLT does not support "custom tags".
If you want to print out anything that is not a literal value, then it must be the result of a function call, wrapped in <xsl:value-of/>
.
精彩评论