<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml Z:\resources\templates\01default_st\gallerymaker.xml?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	xmlns:fn="http://www.w3.org/2005/xpath-functions" 
	xmlns:ag="http://ns.adobe.com/silver/1.0" 
	xmlns:my-ns="http://my.com" 
	xmlns:my-ns2="http://my.com2" 
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	exclude-result-prefixes="my-ns my-ns2"
>
	<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
	<xsl:variable name="empty_string"/>
	<xsl:template match="/">
		<xsl:text>// rendered by gallermakerFlash.xslt
if(AOM.AmgGalleryMaker.currentDocument.aomJsFuncs.amgGalleryMakerData == undefined)
    AOM.AmgGalleryMaker.currentDocument.aomJsFuncs.amgGalleryMakerData = {};
AOM.AmgGalleryMakerData = AOM.AmgGalleryMaker.currentDocument.aomJsFuncs.amgGalleryMakerData;
AOM.AmgGalleryMakerData.models = {};
</xsl:text>
		<xsl:call-template name="identifier" />
		<xsl:call-template name="views" />
		<xsl:call-template name="models"/>
		<xsl:call-template name="bindings" />
		<xsl:call-template name="sizes" />
	</xsl:template>
	<xsl:template name="views">
AOM.AmgGalleryMakerData.views = [
<xsl:for-each select="/galleryMaker/mx:Application/mx:VBox">
			<xsl:apply-templates/>
		</xsl:for-each>];
	</xsl:template>
	
	<xsl:template name="identifier">
AOM.AmgGalleryMakerData.models.identifier = "<xsl:value-of select="/galleryMaker/galleryInfo/identifier/." />";<xsl:text>
</xsl:text>AOM.AmgGalleryMakerData.models.galleryName = <xsl:value-of select="/galleryMaker/galleryInfo/galleryName/." />;<xsl:text>
</xsl:text>
	</xsl:template>
	
	<xsl:template name="models">
AOM.AmgGalleryMakerData.models.galleryMaker = [<xsl:text />
		<xsl:for-each select="/galleryMaker/mx:Application/mx:Model">
			<xsl:call-template name="modelItems">
				<xsl:with-param name="path"><xsl:value-of select="@id"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:for-each>
];
	</xsl:template>

	<xsl:template name="modelItems">
		<xsl:param name="path">undefined</xsl:param>
		<xsl:choose>
			<xsl:when test="not(node())">
				<xsl:choose>
					<xsl:when test="not(string(.))"><xsl:text>
</xsl:text>	{path:"<xsl:value-of select="$path"/>",value:""},</xsl:when>
					<xsl:when test="normalize-space(.) != ''">
						<xsl:if test="not(self::comment())"><xsl:text>
</xsl:text>	{path:"<xsl:value-of select="$path"/>",value:"<xsl:value-of select="."/>"},</xsl:if>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="node()">
				<xsl:for-each select="node()">
					<xsl:variable name="next_path">
						<xsl:value-of select="$path"/>
						<xsl:if test="name() != $empty_string">.<xsl:value-of select="name()"/>
						</xsl:if>
					</xsl:variable>
					<xsl:call-template name="modelItems">
						<xsl:with-param name="path" select="$next_path"/>
					</xsl:call-template>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
	error - template modelItems otherwise...<xsl:text />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	
	<xsl:template name="modelItems_0">
		<xsl:param name="path">undefined</xsl:param>
		<xsl:choose>
			<xsl:when test="not(node())">
				<!--no children-->
				<xsl:choose>
					<xsl:when test="not(string(.))">
						<xsl:value-of select="$path"/> = <xsl:text>''</xsl:text>;
</xsl:when>
					<xsl:when test="normalize-space(.) != ''">
						<xsl:if test="not(self::comment())">
							<xsl:value-of select="$path"/> = '<xsl:value-of select="."/>';
</xsl:if>
					</xsl:when>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="node()">
				<!--children-->
				<xsl:if test="not(text())">
					<xsl:value-of select="$path"/> = {};
				</xsl:if>
				<xsl:for-each select="node()">
					<xsl:variable name="next_path">
						<xsl:value-of select="$path"/>
						<xsl:if test="name() != $empty_string">.<xsl:value-of select="name()"/>
						</xsl:if>
					</xsl:variable>
					<xsl:call-template name="modelItems">
						<xsl:with-param name="path" select="$next_path"/>
					</xsl:call-template>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
error - otherwise.1
</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="bindings">
AOM.AmgGalleryMakerData.bindings = [
<xsl:for-each select="/galleryMaker/mx:Application/mx:Binding">	{"source": "<xsl:value-of select="@source"/>", "destination": "<xsl:value-of select="@destination"/>"},
</xsl:for-each>];
	</xsl:template>
	<xsl:template name="sizes">
AOM.AmgGalleryMakerData.sizes = {};
AOM.AmgGalleryMakerData.sizes.index = [<xsl:for-each select="/galleryMaker/sizes/size">"<xsl:value-of select="@name"/>"<xsl:if test="position() != last()">, </xsl:if>
		</xsl:for-each>];
AOM.AmgGalleryMakerData.sizes.values = {<xsl:for-each select="/galleryMaker/sizes/size">
	"<xsl:value-of select="@name"/>": { "width": <xsl:value-of select="@width"/>, "height": <xsl:value-of select="@height"/> }<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>
};
	</xsl:template>
	<!-- sizes -->
	<!-- view mxml processing -->
	<xsl:template name="defaultMx">
		<xsl:param name="mxType">undefined</xsl:param>	{"type": "<xsl:value-of select="$mxType"/>", "attributes": {<xsl:for-each select="@*"> "<xsl:value-of select="name()"/>": "<xsl:value-of select="."/>"<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>}},
</xsl:template>
	<xsl:template name="HVBox">
	<xsl:param name="boxType">undefined</xsl:param>	{"type": "<xsl:value-of select="$boxType"/>", "attributes": {<xsl:for-each select="@*"> "<xsl:value-of select="name()"/>": "<xsl:value-of select="."/>"<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>},"children":[
	<xsl:apply-templates/>	]},
</xsl:template>
	<xsl:template match="mx:CheckBox">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">checkbox</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:ColorPicker">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">colorpicker</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
<!--
	<xsl:template match="mx:ComboBox">	{"type": "combobox", "attributes": {<xsl:for-each select="@*"> "<xsl:value-of select="name()"/>": "<xsl:value-of select="."/>"<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>},	"values":[
	<xsl:for-each select="./mx:dataProvider/mx:Array">
			<xsl:apply-templates/>
		</xsl:for-each>		]},
</xsl:template>
-->
	<xsl:template match="mx:ComboBox">	{"type": "combobox", "attributes": {<xsl:for-each select="@*"> "<xsl:value-of select="name()"/>": "<xsl:value-of select="."/>"<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>},	"values":[
	<xsl:for-each select="./mx:dataProvider/mx:Array">
		<xsl:apply-templates/>
	</xsl:for-each>		],	"labels":[
	<xsl:for-each select="./ag:popUpItems">
		<xsl:apply-templates/>
	</xsl:for-each>		]},
</xsl:template>
	
	<xsl:template match="mx:String">
		"<xsl:value-of select="." />"<xsl:if test="position() != last()">,</xsl:if>
	</xsl:template>
	<xsl:template match="ag:popUpItem">
		{value: "<xsl:value-of select="@value" />", title: "<xsl:value-of select="@title" />"}<xsl:if test="position() != last()">,</xsl:if>
	</xsl:template>

	<xsl:template match="mx:HBox">
		<xsl:call-template name="HVBox">
			<xsl:with-param name="boxType">hbox</xsl:with-param>
		</xsl:call-template>
</xsl:template>
	<xsl:template match="mx:HRule">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">hrule</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:HSlider">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">hslider</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:Label">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">label</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:Object">			{<xsl:for-each select="@*"> "<xsl:value-of select="name()"/>": "<xsl:value-of select="."/>"<xsl:if test="position() != last()">,</xsl:if>
		</xsl:for-each>},
</xsl:template>
	<xsl:template match="mx:Spacer">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">spacer</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:TextArea">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">textarea</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:TextInput">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">textinput</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	<xsl:template match="mx:VBox">
		<xsl:call-template name="HVBox">
			<xsl:with-param name="boxType">vbox</xsl:with-param>
		</xsl:call-template>
</xsl:template>
	<xsl:template match="mx:*">
		<xsl:call-template name="defaultMx">
			<xsl:with-param name="mxType">unhandled_value(<xsl:value-of select="name()"/>)</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
</xsl:stylesheet>
