/Main/Source/Sandcastle/ProductionTransforms/CreatePrototypeToc.xsl
Extensible Stylesheet Language Transformations | 142 lines | 130 code | 12 blank | 0 comment | 0 complexity | d9b7f70329932baef3cdde246b2d9b43 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
1<?xml version="1.0"?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"> 3 4 <xsl:param name="segregated" select="false()" /> 5 6 <xsl:output indent="yes" /> 7 8 <xsl:key name="index" match="/reflection/apis/api" use="@id" /> 9 10 <xsl:template match="/"> 11 <topics> 12 <xsl:choose> 13 <xsl:when test="count(/reflection/apis/api[apidata/@group='root']) > 0"> 14 <xsl:apply-templates select="/reflection/apis/api[apidata/@group='root']" /> 15 </xsl:when> 16 <xsl:when test="count(/reflection/apis/api[apidata/@group='namespace']) > 0"> 17 <xsl:apply-templates select="/reflection/apis/api[apidata/@group='namespace']"> 18 <xsl:sort select="apidata/@name" /> 19 </xsl:apply-templates> 20 </xsl:when> 21 <xsl:otherwise> 22 <xsl:apply-templates select="/reflection/apis/api[apidata/@group='type']"> 23 <xsl:sort select="apidata/@name" /> 24 </xsl:apply-templates> 25 </xsl:otherwise> 26 </xsl:choose> 27 </topics> 28 </xsl:template> 29 30 <!-- create a root entry and namespace sub-entries --> 31 <xsl:template match="api[apidata/@group='root']"> 32 <topic id="{@id}" file="{file/@name}"> 33 <xsl:apply-templates select="key('index',elements/element/@api)"> 34 <xsl:sort select="apidata/@name" /> 35 </xsl:apply-templates> 36 </topic> 37 </xsl:template> 38 39 40 <!-- for each namespace, create namespace entry and type sub-entries --> 41 <xsl:template match="api[apidata/@group='namespace']"> 42 <topic id="{@id}" file="{file/@name}"> 43 <xsl:apply-templates select="key('index',elements/element/@api)"> 44 <xsl:sort select="@id" /> 45 </xsl:apply-templates> 46 </topic> 47 </xsl:template> 48 49 <!-- for each type, create type entry and either overload entries or member entries as sub-entries --> 50 <xsl:template match="api[apidata/@group='type']"> 51 <xsl:choose> 52 <xsl:when test="$segregated"> 53 <stopic id="{@id}" project="{containers/library/@assembly}" file="{file/@name}"> 54 <xsl:call-template name="processType" /> 55 </stopic> 56 </xsl:when> 57 <xsl:otherwise> 58 <topic id="{@id}" file="{file/@name}"> 59 <xsl:call-template name="processType" /> 60 </topic> 61 </xsl:otherwise> 62 </xsl:choose> 63 </xsl:template> 64 65 <xsl:template name="processType"> 66 <xsl:variable name="typeId" select="@id" /> 67 <xsl:variable name="members" select="key('index',elements/element/@api)[containers/type/@api=$typeId]" /> 68 <xsl:for-each select="$members"> 69 <xsl:sort select="apidata/@name" /> 70 <xsl:variable name="name" select="apidata/@name" /> 71 <xsl:variable name="subgroup" select="apidata/@subgroup" /> 72 <xsl:variable name="set" select="$members[apidata/@name=$name and apidata/@subgroup=$subgroup]" /> 73 <xsl:choose> 74 <xsl:when test="count($set) > 1"> 75 <xsl:if test="($set[1]/@id)=@id"> 76 <xsl:variable name="overloadId"> 77 <xsl:value-of select="overload/@api" /> 78 </xsl:variable> 79 <xsl:choose> 80 <xsl:when test="$segregated"> 81 <stopic id="{@id}" project="{containers/library/@assembly}" file="{key('index',$overloadId)/file/@name}"> 82 <xsl:for-each select="$set"> 83 <xsl:apply-templates select="." /> 84 </xsl:for-each> 85 </stopic> 86 </xsl:when> 87 <xsl:otherwise> 88 <topic id="{@id}" file="{key('index',$overloadId)/file/@name}"> 89 <xsl:for-each select="$set"> 90 <xsl:apply-templates select="." /> 91 </xsl:for-each> 92 </topic> 93 </xsl:otherwise> 94 </xsl:choose> 95 </xsl:if> 96 </xsl:when> 97 <xsl:otherwise> 98 <xsl:apply-templates select="." /> 99 </xsl:otherwise> 100 </xsl:choose> 101 </xsl:for-each> 102 </xsl:template> 103 104 <!-- for each member, create a leaf entry --> 105 <xsl:template match="api[apidata/@group='member']"> 106 <xsl:choose> 107 <xsl:when test="$segregated"> 108 <stopic id="{@id}" project="{containers/library/@assembly}" file="{file/@name}" /> 109 </xsl:when> 110 <xsl:otherwise> 111 <topic id="{@id}" file="{file/@name}" /> 112 </xsl:otherwise> 113 </xsl:choose> 114 </xsl:template> 115 116 <xsl:template name="overloadId"> 117 <xsl:param name="memberId" /> 118 <xsl:text>Overload:</xsl:text> 119 <xsl:variable name="noParameters"> 120 <xsl:choose> 121 <xsl:when test="contains($memberId,'(')"> 122 <xsl:value-of select="substring-before($memberId,'(')" /> 123 </xsl:when> 124 <xsl:otherwise> 125 <xsl:value-of select="$memberId" /> 126 </xsl:otherwise> 127 </xsl:choose> 128 </xsl:variable> 129 <xsl:variable name="noGeneric"> 130 <xsl:choose> 131 <xsl:when test="contains($noParameters,'``')"> 132 <xsl:value-of select="substring-before($noParameters,'``')" /> 133 </xsl:when> 134 <xsl:otherwise> 135 <xsl:value-of select="$noParameters" /> 136 </xsl:otherwise> 137 </xsl:choose> 138 </xsl:variable> 139 <xsl:value-of select="substring($noGeneric,3)" /> 140 </xsl:template> 141 142</xsl:stylesheet>