Visual Studio中对C#语言可以很方便地添加注释,而且可以自动生成XML的文档,可是XML文档看起来很不方便,如果通过XSL转换成一定格式的HTML文档看着就方便了。在网上查了几次也没有找一以一个可用的XSL。这几天有点空,一急之下就一连看着XSL的手册,找了两个简单的XSL例子,就自己写了一个,虽然转换还不太全,但普通的信息还是可以转换的。
首先,在xml文档中加入对样式的引用:
<?xml-stylesheet href='help.xsl' type='text/xsl' media='screen'?>
然后将help.xls放到XML所在目录,打开XML即可看到已经转换好的HTML格式,help.xls文件内容即:
<?xml version="1.0" encoding="utf-8"?>
<!-- <br /> Visual Studio XML program document translator <br /> Copyright (c) 2003, Nocky Tian <br /> version: 0.1 <br /> Nocky Tian(<a href="mailto:tiandezhen@gmail.com">tiandezhen@gmail.com</a>) <br /> 2007-10-31 <br />-->
<stylesheet version="1.0"></stylesheet> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<template match="doc"><br><br><br><title> <br> Help - Visual Sutdio XML program docuemnt translator <br> </title> <br><style> <br /> h2{ <br /> background-color:White; <br /> vertical-align:text-bottom; <br /> } <br /> h3{ <br /> background-color:#E0E0E0;} <br /> ul{ <br /> list-style-type:none; <br /> } <br /> pre{ <br /> maxWidth:800px; <br /> } <br /> a:hover{ color:Red; text-decoration:underline;} <br /> a:link {color:Black; text-decoration:none;} <br /> a:visited{ color:Gray; text-decoration:none;}</p> <p> a.gray:hover{ color:Red; text-decoration:underline;} <br /> a.gray:link{ color:Gray;text-decoration:none;} <br /> a.gray:visited{ color:Gray; text-decoration:none;}</p> <p> </style> <br><br><br><div style="color:Gray; width:300px; float:right; text-align:left"> <br> Visual Studio XML program document translator<br><br> Copyright (c) 2007, Nocky Tian<br><br> version: 0.1<br><br><a href="<a%20href=" mailto:tiandezhen>mailto:tiandezhen@gmail.com</a>" class="gray">Nocky Tian <br><br> 2007-10-31<br><br> </div></template>
<for-each select="assembly"><br><h1> <br><value-of select="name"></value-of><br> </h1> <br></for-each>
Type List:
<for-each select="//member[contains(@name,'T:')]"><br><li> <br><div style="width:30px; float:left"> <br><img title="Properties:" src="images/class.bmp"><br> </div> <br><div style="float:left; width:250px"> <br><strong> <br><choose><br><when test="contains(@name,'.')"><br><a href="<a%20href=" mailto:>#{@name</a>}"> <br><value-of select="substring-after(@name,'.')"></value-of><br><br></when><br><otherwise><br><value-of select="@name"></value-of><br></otherwise><br></choose><br></strong> <br> </div> <br><div style="float:left"> <br><value-of select="summary"></value-of><br> </div> <br> </li> <br></for-each>
<for-each select="members"><br><!-- type info --><br><for-each select="member[contains(@name,'T:')]"><br><variable name="className" select="substring-after(@name,':')"><br></variable><br><div> <br><br><br><br><br><a name="<a%20href=" mailto:>{@name}"></a>> <br><div style="width:100%"> <br><div style="float:left; width:500px"> <br><h2> <br><!--<xsl:value-of select="substring-after(@name,':')"/>--><br><img src="images/class.bmp"><br><value-of select="$className"></value-of><br> </h2> <br> </div> <br><div style="float:right; verticle-align:text-bottom"> <br><a class="gray" href="#TypeList">Type List</a> <br> </div> <br> </div> <br><div style="width:100%"> <br><hr style="line-height:2px;color:black"> <br><hr style="line-height:2px;color:black"> <br> </div> <br><if test="count(summary)>0"><br><h3> <br> Summary: <br> </h3> <br><pre> <br><value-of select="summary"></value-of><br></pre> <br></if><br><if test="count(remarks)>0"><br><h3> <br> Remarks: <br> </h3> <br><pre> <br><value-of select="remarks"></value-of><br></pre> <br></if><br><hr> <br><if test="count(//member[(substring-before(@name,':')='M') and contains(@name,$className)])>0"><br><a name="methodList"></a> <br><h3>Methods:</h3> <br><ul style="list-style-type:none"> <br><for-each select="//member[(substring-before(@name,':')='M') and contains(@name,$className)]"><br><li> <br><div style="width:30px; float:left"> <br><img title="Properties:" src="images/method.bmp"><br> </div> <br><variable name="memberName" select="substring-after(@name, $className)"></variable><br><div style="float:left; width:200px"> <br><choose><br><when test="contains($memberName,'(')"><br><a href="<a%20href=" mailto:>#{@name</a>}"> <br><value-of select="substring-before(substring-after($memberName,'.'),'(')"></value-of><br><br></when><br><otherwise><br><a href="<a%20href=" mailto:>#{@name</a>}"> <br><value-of select="substring-after($memberName,'.')"></value-of><br><br></otherwise><br></choose><br> </div> <br><div style="float:left"> <br><value-of select="summary"></value-of><br> </div> <br> </li> <br></for-each><br> </ul> <br></if><p> <if test="count(//member[(substring-before(@name,':')='P') and contains(@name,$className)])>0"><br><h3>Properties:</h3> <br><ul style="list-style-type:none"> <br><for-each select="//member[(substring-before(@name,':')='P') and contains(@name,$className)]"><br><li> <br><div style="width:30px; float:left"> <br><img title="Properties:" src="images/property.bmp"><br> </div> <br><div style="float:left; width:200px"> <br><variable name="memberName" select="substring-after(@name, $className)"></variable><br><a href="<a%20href=" mailto:>#{@name</a>}"> <br><value-of select="substring-after($memberName,'.')"></value-of><br><br> </div> <br><div style="float:left"> <br><value-of select="."></value-of><br> </div> <br> </li> <br></for-each><br> </ul> <br></if><br><!-- events list --><br><if test="count(//member[(substring-before(@name,':')='E') and contains(@name,$className)])>0"><br><a name="eventList"></a> <br><h3>Events:</h3> <br><ul> <br><for-each select="//member[(substring-before(@name,':')='E') and contains(@name,$className)]"><br><li> <br><variable name="memberName" select="substring-after(@name, $className)"></variable><br><div style="width:30px; float:left"> <br><img title="Properties:" src="images/event.bmp"><br> </div> <br><div style="float:left; width:200px"> <br><a href="<a%20href=" mailto:>#{@name</a>}"> <br><value-of select="substring-after($memberName,'.')"></value-of><br><br> </div> <br> </li> <br></for-each><br> </ul> <br></if><br><!-- examples --><br><for-each select="example"><br><pre style="font-family:Courier New,Courier"> <br><value-of select="."></value-of><br></pre> <br></for-each></p> <p> </p> <hr> <br><!-- details --><br><if test="count(//member[(substring-before(@name,':')='M') and contains(@name,$className)])>0"><br><h3>Methods:</h3> <br><for-each select="//member[(substring-before(@name,':')='M') and contains(@name,$className)]"><br><variable name="memberName" select="substring-after(@name, $className)"></variable><br><a name="<a%20href=" mailto:>{@name}"></a>> <br><variable name="methodName" select="substring-after($memberName,'.')"></variable><br><div style="width:100%"> <br><div style="float:left"> <br><h4> <br><value-of select="$methodName"></value-of><br> </h4> <br> </div> <br><div style="float:right; width:150px"> <br><a class="gray" href="#methodList">Method List</a> <br> </div> <br> </div> <p> <!-- summary --> <br><for-each select="summary"><br><pre> <br><value-of select="."></value-of><br></pre> <br></for-each><br><for-each select="remarks"><br><div> <br> Remarks: <br> </div> <br><pre> <br><value-of select="."></value-of><br></pre> <br></for-each><br><!-- parameters --><br><if test="count(param) > 0"><br><div>Parameters:</div> <br><ul> <br><for-each select="param"><br><li> <br><div style="float:left; width:100px"> <br><i> <br><value-of select="@name"></value-of><br></i>: <br> </div> <br><div style="float:left;"> <br><value-of select="../param"></value-of><br> </div> <br> </li> <br></for-each><br> </ul> <br></if><br><!-- returns --><br><if test="count(returns)> 0"><br><div>Returns:</div> <br><pre> <br><value-of select="returns"></value-of><br></pre> <br></if><br><!-- examples --><br><for-each select="example"><br><div> <br><example>Examples:</example><br> </div> <br><pre style="font-family:Courier New,Courier"> <br><value-of select="."></value-of><br></pre> <br></for-each></p> <p> </p></for-each><br></if><br><!-- event details--><br><if test="count(//member[(substring-before(@name,':')='E') and contains(@name,$className)])>0"><br><h3>Events:</h3> <br><for-each select="//member[(substring-before(@name,':')='E') and contains(@name,$className)]"><br><variable name="memberName" select="substring-after(@name, $className)"></variable><br><a name="<a%20href=" mailto:>{@name}"></a>> <br><variable name="methodName" select="substring-after($memberName,'.')"></variable><br><div style="width:100%"> <br><div style="float:left"> <br><h4> <br><value-of select="$methodName"></value-of><br> </h4> <br> </div> <br><div style="float:right; width:150px"> <br><a class="gray" href="#eventList">Event List</a> <br> </div> <br> </div> <br><!-- summary --><br><for-each select="summary"><br><pre> <br><value-of select="."></value-of><br></pre> <br></for-each><br><for-each select="remarks"><br><div> <br> Remarks: <br> </div> <br><pre> <br><value-of select="."></value-of><br></pre> <br></for-each><br><!-- parameters --><br><if test="count(param) > 0"><br><div>Parameters:</div> <br><ul> <br><for-each select="param"><br><li> <br><div style="float:left; width:100px"> <br><i> <br><value-of select="@name"></value-of><br></i>: <br> </div> <br><div style="float:left;"> <br><value-of select="../param"></value-of><br> </div> <br> </li> <br></for-each><br> </ul> <br></if><br><!-- examples --><br><for-each select="example"><br><div> <br><example>Examples:</example><br> </div> <br><pre style="font-family:Courier New,Courier"> <br><value-of select="."></value-of><br></pre> <br></for-each><p> </p></for-each><br></if><p> </p> </div> <br></for-each><br></for-each>