summaryrefslogtreecommitdiffstats
path: root/tools/Sandcastle/ProductionTransforms/AddGuidFilenames.xsl
blob: b378cce299c4d005d5dec1987d075fde8a4c8151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0"?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:ddue="urn:ddue-extensions"
	version="1.1">

	<msxsl:script language="C#" implements-prefix="ddue">
		<msxsl:using namespace="System.Security.Cryptography" />
		<![CDATA[
			public static string getFileName(string id) {
				HashAlgorithm md5 = HashAlgorithm.Create("MD5");
				byte[] input = Encoding.UTF8.GetBytes(id);
				byte[] output = md5.ComputeHash(input);
				Guid guid = new Guid(output);
				return( guid.ToString() );
			}
		]]>
	</msxsl:script>

	<xsl:output indent="yes" encoding="UTF-8" />
	
	<xsl:template match="/">
		<reflection>
			<xsl:apply-templates select="/reflection/assemblies" />
			<xsl:apply-templates select="/reflection/apis" />
		</reflection>
	</xsl:template>

	<xsl:template match="assemblies">
		<xsl:copy-of select="." />
	</xsl:template>

	<xsl:template match="apis">
		<apis>
			<xsl:apply-templates select="api" />
		</apis>
	</xsl:template>

	<xsl:template match="api">
		<api id="{@id}">
			<xsl:copy-of select="*" />
			<file name="{ddue:getFileName(@id)}" />
		</api>
	</xsl:template>

</xsl:stylesheet>