github.com/puellanivis/breton@v0.2.16/lib/net/dash/mpd/mpd.xslt (about) 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- Generated LXT parser v3.0: do not alter directly --> 3 4 <xsl:stylesheet version="1.0" xmlns:install="http://www.microsoft.com/support" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 5 6 <xsl:variable name="nl"> 7 <xsl:text> 8 </xsl:text> 9 </xsl:variable> 10 11 12 <xsl:output encoding="UTF-8" indent="yes" media-type="application/xml" method="text" version="1.0" /> 13 14 <xsl:template match="/"> 15 <xsl:text>// Code generated by XSLT from DASH-MPD.xml. DO NOT EDIT.</xsl:text> 16 <xsl:value-of select="$nl" /> 17 <xsl:text>// Package mpd is an autogenerated implementation of the DASH-schema.</xsl:text> 18 <xsl:value-of select="$nl" /> 19 <xsl:text>package mpd</xsl:text> 20 <xsl:value-of select="$nl" /> 21 <xsl:value-of select="$nl" /> 22 <xsl:text>import (</xsl:text> 23 <xsl:value-of select="$nl" /> 24 <xsl:text> "regexp"</xsl:text> 25 <xsl:value-of select="$nl" /> 26 <xsl:text> "time"</xsl:text> 27 <xsl:value-of select="$nl" /> 28 <xsl:text>)</xsl:text> 29 <xsl:value-of select="$nl" /> 30 <xsl:value-of select="$nl" /> 31 <xsl:text>// Reference imports to suppress errors if they are not otherwise used.</xsl:text> 32 <xsl:value-of select="$nl" /> 33 <xsl:text>var _ = regexp.MustCompile</xsl:text> 34 <xsl:value-of select="$nl" /> 35 <xsl:text>var _ = time.Second</xsl:text> 36 <xsl:value-of select="$nl" /> 37 <xsl:value-of select="$nl" /> 38 <xsl:text>// mostly computer generated from from http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd</xsl:text> 39 <xsl:value-of select="$nl" /> 40 <xsl:value-of select="$nl" /> 41 <xsl:apply-templates /> 42 </xsl:template> 43 44 <xsl:template match="/xs:schema"> 45 <xsl:for-each select="xs:simpleType"> 46 <xsl:call-template name="simpleType" /> 47 </xsl:for-each> 48 <xsl:for-each select="xs:complexType"> 49 <xsl:call-template name="complexType" /> 50 </xsl:for-each> 51 </xsl:template> 52 53 <xsl:template name="stripType"> 54 <xsl:param name="type" select="@type" /> 55 56 <xsl:choose> 57 <xsl:when test="substring($type,string-length($type) - 3) = "type""> 58 <xsl:value-of select="substring($type,1,string-length($type) - 4)" /> 59 </xsl:when> 60 <xsl:when test="substring($type,string-length($type) - 3) = "Type""> 61 <xsl:value-of select="substring($type,1,string-length($type) - 4)" /> 62 </xsl:when> 63 <xsl:otherwise> 64 <xsl:value-of select="$type" /> 65 </xsl:otherwise> 66 </xsl:choose> 67 </xsl:template> 68 69 <xsl:template name="mapType"> 70 <xsl:param name="type" select="@type" /> 71 72 <xsl:choose> 73 <xsl:when test="$type = "xs:boolean"">bool</xsl:when> 74 <xsl:when test="$type = "xs:string"">string</xsl:when> 75 <xsl:when test="$type = "xs:anyURI"">string</xsl:when> 76 <xsl:when test="$type = "xs:language"">string</xsl:when> 77 <xsl:when test="$type = "xs:integer"">int</xsl:when> 78 <xsl:when test="$type = "xs:unsignedInt"">uint</xsl:when> 79 <xsl:when test="$type = "xs:unsignedLong"">uint64</xsl:when> 80 <xsl:when test="$type = "xs:double"">float64</xsl:when> 81 <xsl:when test="$type = "xs:dateTime"">time.Time</xsl:when> 82 <xsl:when test="$type = "xs:duration"">Duration</xsl:when> 83 <xsl:when test="count(//xs:complexType[@name = $type])"> 84 <xsl:text>*</xsl:text> 85 <xsl:call-template name="stripType"> 86 <xsl:with-param name="type" select="$type" /> 87 </xsl:call-template> 88 </xsl:when> 89 <xsl:otherwise> 90 <xsl:call-template name="stripType"> 91 <xsl:with-param name="type" select="$type" /> 92 </xsl:call-template> 93 </xsl:otherwise> 94 </xsl:choose> 95 </xsl:template> 96 97 <xsl:template name="unionType"> 98 <xsl:param name="members"></xsl:param> 99 100 <xsl:variable name="before" select="substring-before($members," ")" /> 101 <xsl:variable name="type"> 102 <xsl:choose> 103 <xsl:when test="$before = """> 104 <xsl:value-of select="$members" /> 105 </xsl:when> 106 <xsl:otherwise> 107 <xsl:value-of select="$before" /> 108 </xsl:otherwise> 109 </xsl:choose> 110 </xsl:variable> 111 <xsl:variable name="after" select="substring-after($members," ")" /> 112 <xsl:text> // </xsl:text> 113 <xsl:call-template name="mapType"> 114 <xsl:with-param name="type" select="$type" /> 115 </xsl:call-template> 116 <xsl:value-of select="$nl" /> 117 <xsl:if test="$after != """> 118 <xsl:call-template name="unionType"> 119 <xsl:with-param name="members" select="$after" /> 120 </xsl:call-template> 121 </xsl:if> 122 </xsl:template> 123 124 <xsl:template name="simpleType"> 125 <xsl:variable name="name"> 126 <xsl:call-template name="stripType"> 127 <xsl:with-param name="type" select="@name" /> 128 </xsl:call-template> 129 </xsl:variable> 130 <xsl:text>type </xsl:text> 131 <xsl:value-of select="$name" /> 132 <xsl:text> </xsl:text> 133 <xsl:choose> 134 <xsl:when test="count(xs:list) > 0"> 135 <xsl:text>[]</xsl:text> 136 <xsl:call-template name="mapType"> 137 <xsl:with-param name="type" select="xs:list/@itemType" /> 138 </xsl:call-template> 139 </xsl:when> 140 <xsl:when test="count(xs:union) > 0"> 141 <xsl:text>string // union {</xsl:text> 142 <xsl:value-of select="$nl" /> 143 <xsl:call-template name="unionType"> 144 <xsl:with-param name="members" select="xs:union/@memberTypes" /> 145 </xsl:call-template> 146 <xsl:text>// }</xsl:text> 147 </xsl:when> 148 <xsl:otherwise> 149 <xsl:call-template name="mapType"> 150 <xsl:with-param name="type" select="xs:restriction/@base" /> 151 </xsl:call-template> 152 </xsl:otherwise> 153 </xsl:choose> 154 <xsl:value-of select="$nl" /> 155 <xsl:for-each select="xs:restriction"> 156 <xsl:call-template name="restrictions"> 157 <xsl:with-param name="name" select="$name" /> 158 </xsl:call-template> 159 </xsl:for-each> 160 <xsl:value-of select="$nl" /> 161 </xsl:template> 162 163 <xsl:template name="restrictions"> 164 <xsl:param name="name" select="@name" /> 165 166 <xsl:if test="count(xs:enumeration) > 0"> 167 <xsl:text>var </xsl:text> 168 <xsl:value-of select="$name" /> 169 <xsl:text>_Valid = map[string]bool {</xsl:text> 170 <xsl:value-of select="$nl" /> 171 <xsl:for-each select="xs:enumeration"> 172 <xsl:text> "</xsl:text> 173 <xsl:value-of select="@value" /> 174 <xsl:text>": true,</xsl:text> 175 <xsl:value-of select="$nl" /> 176 </xsl:for-each> 177 <xsl:text>}</xsl:text> 178 </xsl:if> 179 <xsl:if test="count(xs:pattern) > 0"> 180 <xsl:text>var </xsl:text> 181 <xsl:value-of select="$name" /> 182 <xsl:text>_Validate = regexp.MustCompile(`</xsl:text> 183 <xsl:value-of select="xs:pattern/@value" /> 184 <xsl:text>`)</xsl:text> 185 </xsl:if> 186 <xsl:if test="count(xs:minInclusive) + count(xs:maxInclusive) + count(xs:minExclusive) + count(xs:maxExclusive)"> 187 <xsl:text>const (</xsl:text> 188 <xsl:value-of select="$nl" /> 189 <xsl:if test="count(xs:minInclusive)"> 190 <xsl:text> </xsl:text> 191 <xsl:value-of select="$name" /> 192 <xsl:text>_MinInclusive </xsl:text> 193 <xsl:value-of select="$name" /> 194 <xsl:text> = </xsl:text> 195 <xsl:value-of select="xs:minInclusive/@value" /> 196 <xsl:value-of select="$nl" /> 197 </xsl:if> 198 <xsl:if test="count(xs:maxInclusive)"> 199 <xsl:text> </xsl:text> 200 <xsl:value-of select="$name" /> 201 <xsl:text>_MaxInclusive </xsl:text> 202 <xsl:value-of select="$name" /> 203 <xsl:text> = </xsl:text> 204 <xsl:value-of select="xs:maxInclusive/@value" /> 205 <xsl:value-of select="$nl" /> 206 </xsl:if> 207 <xsl:if test="count(xs:minExclusive)"> 208 <xsl:text> </xsl:text> 209 <xsl:value-of select="$name" /> 210 <xsl:text>_MinExclusive </xsl:text> 211 <xsl:value-of select="$name" /> 212 <xsl:text> = </xsl:text> 213 <xsl:value-of select="xs:minExclusive/@value" /> 214 <xsl:value-of select="$nl" /> 215 </xsl:if> 216 <xsl:if test="count(xs:maxExclusive)"> 217 <xsl:text> </xsl:text> 218 <xsl:value-of select="$name" /> 219 <xsl:text>_MaxExclusive </xsl:text> 220 <xsl:value-of select="$name" /> 221 <xsl:text> = </xsl:text> 222 <xsl:value-of select="xs:maxExclusive/@value" /> 223 <xsl:value-of select="$nl" /> 224 </xsl:if> 225 <xsl:text>)</xsl:text> 226 </xsl:if> 227 <xsl:value-of select="$nl" /> 228 </xsl:template> 229 230 <xsl:template name="exportName"> 231 <xsl:param name="name" select="@name" /> 232 233 <xsl:value-of select="concat(translate(substring($name,1,1),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWYYZ"),substring($name,2))" /> 234 </xsl:template> 235 236 <xsl:template name="simpleContent"> 237 <xsl:for-each select="xs:attribute[@name]"> 238 <xsl:text> </xsl:text> 239 <xsl:call-template name="exportName"> 240 <xsl:with-param name="name" select="@name" /> 241 </xsl:call-template> 242 <xsl:text> </xsl:text> 243 <xsl:call-template name="mapType"> 244 <xsl:with-param name="type" select="@type" /> 245 </xsl:call-template> 246 <xsl:text> `xml:"</xsl:text> 247 <xsl:value-of select="@name" /> 248 <xsl:text>,attr</xsl:text> 249 <xsl:if test="count(@use) = 0 or @use != "required""> 250 <xsl:text>,omitempty</xsl:text> 251 </xsl:if> 252 <xsl:text>"`</xsl:text> 253 <xsl:if test="count(@default)"> 254 <xsl:text> // default: </xsl:text> 255 <xsl:value-of select="@default" /> 256 </xsl:if> 257 <xsl:value-of select="$nl" /> 258 </xsl:for-each> 259 </xsl:template> 260 261 <xsl:template name="complexContent"> 262 <xsl:for-each select="xs:sequence/xs:element"> 263 <xsl:text> </xsl:text> 264 <xsl:call-template name="exportName"> 265 <xsl:with-param name="name" select="@name" /> 266 </xsl:call-template> 267 <xsl:text> </xsl:text> 268 <xsl:if test="@maxOccurs = "unbounded" or @maxOccurs > 1"> 269 <xsl:text>[]</xsl:text> 270 </xsl:if> 271 <xsl:choose> 272 <xsl:when test="count(xs:complexType) > 0"> 273 <xsl:text>struct {</xsl:text> 274 <xsl:value-of select="$nl" /> 275 <xsl:for-each select="xs:complexType"> 276 <xsl:call-template name="complexContent" /> 277 </xsl:for-each> 278 <xsl:text> }</xsl:text> 279 <xsl:value-of select="$nl" /> 280 </xsl:when> 281 <xsl:otherwise> 282 <xsl:call-template name="mapType"> 283 <xsl:with-param name="type" select="@type" /> 284 </xsl:call-template> 285 <xsl:text> `xml:"</xsl:text> 286 <xsl:value-of select="@name" /> 287 <xsl:if test="count(@minOccurs) and @minOccurs = 0">,omitempty</xsl:if> 288 <xsl:text>"`</xsl:text> 289 <xsl:value-of select="$nl" /> 290 </xsl:otherwise> 291 </xsl:choose> 292 </xsl:for-each> 293 <xsl:if test="count(xs:sequence/xs:element) > 0 and count(xs:attribute[@name]) > 0"> 294 <xsl:value-of select="$nl" /> 295 </xsl:if> 296 <xsl:call-template name="simpleContent" /> 297 </xsl:template> 298 299 <xsl:template name="complexType"> 300 <xsl:text>type </xsl:text> 301 <xsl:call-template name="stripType"> 302 <xsl:with-param name="type" select="@name" /> 303 </xsl:call-template> 304 <xsl:text> struct {</xsl:text> 305 <xsl:value-of select="$nl" /> 306 <xsl:for-each select="xs:complexContent/xs:extension"> 307 <xsl:text> </xsl:text> 308 <xsl:call-template name="mapType"> 309 <xsl:with-param name="type" select="@base" /> 310 </xsl:call-template> 311 <xsl:value-of select="$nl" /> 312 <xsl:value-of select="$nl" /> 313 <xsl:call-template name="complexContent" /> 314 </xsl:for-each> 315 <xsl:for-each select="xs:simpleContent/xs:extension"> 316 <xsl:text> CDATA </xsl:text> 317 <xsl:call-template name="mapType"> 318 <xsl:with-param name="type" select="@base" /> 319 </xsl:call-template> 320 <xsl:text> `xml:",chardata"`</xsl:text> 321 <xsl:value-of select="$nl" /> 322 <xsl:value-of select="$nl" /> 323 <xsl:call-template name="simpleContent" /> 324 </xsl:for-each> 325 <xsl:call-template name="complexContent" /> 326 <xsl:text>}</xsl:text> 327 <xsl:value-of select="$nl" /> 328 <xsl:value-of select="$nl" /> 329 </xsl:template> 330 331 </xsl:stylesheet>