How do I place example code in a code file that is language specific. For example:
public class MyTester()
{
<SUMMARY>Test Method</SUMMARY>
<EXAMPLE>
<PARA>C#</PARA>
<CODE>
MyTester tester = new MyTester();
test.Test();
</CODE>
<PARA>VB</PARA>
<CODE>
Dim tester As MyTester = New MyTester()
test.Test()
</CODE>
</EXAMPLE>
public void Test() {}
}
I would like to be able to do this so that users of my documentation can filter on the language which they want to see. I have noticed that the MSDN site works this way which leds me to believe that it can be done. Can some one shed some light on how this is done.
Thanks
John

Example code and it's language
JVJ
The code works great, thank you, but I needed to add "Copy Code" to your code above. I would like to also have in the syntaxCodeBlocks (Declarations) the "Copy Code" icon and text just like (some) declarations in MSDN. It would be nice to have colorization of the code like Eric Woodruff has done. It would also be nice to be able to turn on and off the line numbers at will other than by project.
As for the reference to scriptlets I can not find it any more. I may have been looking at another persons code and not the Dec CTP. :-)
BTW - The icon "copycodeHighlight.gif" needs to be added to the Presentation icons folders in the Feb CTP.
Noral
Ryan F
You can try what I suggested and will work if you use the convetion I described in the CS file for /// comments. Yes they will get the icon and the code examples will be in the correct order.
Not sure about your question on reference to scriptelets
Anand..
antxxxx
I have implemented this functionality along with some other features for Sandcastle in a couple of custom build components. You can find the full details in this article: http://www.codeproject.com/useritems/SandcastleComponents.asp. It doesn't have a "Copy Code" button but if you can supply me with a link to an example, I can take a look at implementing it in a future release.
In the article, you can skip down to the the section titled "The Supplied Build Components" if you aren't interested in how to actually write one. The code and the components themselves can be downloaded from http://www.codeplex.com/SHFB. The components are integrated with the help file builder too so if you're using it, there's nothing to do. If using them in your own build scripts, you'll need to add the necessary sections to the sandcastle.config file. The article describes how to do that.
Note that I have made some changes recently to add some new features and fix some bugs. These will be available in the 1.4.0.0 release due shortly after the next Sandcastle CTP at the end of the month.
Eric
Joel Martinez
Noral,
Depending on what the Sandcastle customers have in their /// comments the fix needs change to the main_Sandcastle. xsl transform. For example if we have something like:
public class MyTester()
{
<summary>Test Method</summary>
<example>
<code language="vb">
Dim tester As MyTester = New MyTester()
test.Test()
</code>
<code language="c#">
MyTester tester = new MyTester();
test.Test();
</code>
</example>
public void Test() {}
}
then in the transforms [main_sandcastle.xsl] we need to update the ‘code’ template as:
<xsl:template match="code">
<xsl:variable name="codeLang">
<xsl:choose>
<xsl:when test="@language = 'vbs'">
<xsl:text>VBScript</xsl:text>
</xsl:when>
<xsl:when test="@language = 'vb' or @language = 'vb#' or @language = 'VB'" >
<xsl:text>VisualBasic</xsl:text>
</xsl:when>
<xsl:when test="@language = 'c#' or @language = 'cs' or @language = 'C#'" >
<xsl:text>CSharp</xsl:text>
</xsl:when>
<xsl:when test="@language = 'cpp' or @language = 'cpp#' or @language = 'c' or @language = 'c++' or @language = 'C++'" >
<xsl:text>ManagedCPlusPlus</xsl:text>
</xsl:when>
<xsl:when test="@language = 'j#' or @language = 'jsharp'">
<xsl:text>JSharp</xsl:text>
</xsl:when>
<xsl:when test="@language = 'js' or @language = 'jscript#' or @language = 'jscript' or @language = 'JScript'">
<xsl:text>JScript</xsl:text>
</xsl:when>
<xsl:when test="@language = 'xml'">
<xsl:text>xml</xsl:text>
</xsl:when>
<xsl:when test="@language = 'html'">
<xsl:text>html</xsl:text>
</xsl:when>
<xsl:when test="@language = 'vb-c#'">
<xsl:text>visualbasicANDcsharp</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>other</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="code">
<span codeLanguage="{$codeLang}">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<th>
<include item="{$codeLang}"/>
<xsl:text> </xsl:text>
</th>
<th>
<span class="copyCode" onclick="CopyCode(this)" onkeypress="CopyCode_CheckKey(this, event)" onmouseover="ChangeCopyCodeIcon(this)" onmouseout="ChangeCopyCodeIcon(this)" tabindex="0">
<img class="copyCodeImage" name="ccImage" align="absmiddle">
<includeAttribute name="alt" item="CopyCodeImage" />
<includeAttribute name="src" item="iconPath">
<parameter>copycode.gif</parameter>
</includeAttribute>
</img>
<include item="copyCode"/>
</span>
</th>
</tr>
<tr>
<td colspan="2">
<pre>
<xsl:apply-templates/>
</pre>
</td>
</tr>
</table>
</span>
</div>
</xsl:template>
The one I presented above in highlighted section is the general standard we use for conceptual/mangedreference topics inside Microsoft. If customers are willing to adopt this convetion then I will be happy to make this change.
Anand..
fMarkf
Anand,
Do you have an update on this
Thank you,
Noral
jwaddell
Hi Anand
Please make sure that copycodeHighlight.gif is also in the Feb CTP.
Noral
A.Russell
R.K.S.
Thank you for the reply Eric however I am looking for a Microsoft response on this topic.
Since the project is so fluid right now I am not considering any add-ons/workarounds/hacks.
Noral
h1
Thanks you Anand.
I know I am willing to make this the convention. Can you answer me these questions...Will Sandcastle put them(the code examples) in the correct order for you...ie Visual Basic, C#, C++, J#, etc or will they be put into the help file the same way they are layed out in the code And will the declarations get the "Copy Code" link and icon
I was also poking around and I saw some references to scriplets...do you doument those the same way or are they consider equivelent
Thank again,
Noral
CJira
Thanks Noral and we are rolling this fix for Feb CTP
Anand..
Bill Gates II
We can enable this using a custom tag in Sandcastle. I will add this as a feature request for Sandcastle.
Anand..