<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp   "&#160;">
<!ENTITY lsaquo   "&#8249;">
<!ENTITY rsaquo   "&#8250;">
<!ENTITY laquo  "&#171;">
<!ENTITY raquo  "&#187;">
<!ENTITY copy   "&#169;">
]>
<xsl:stylesheet version="3.0"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				xmlns:ou="http://omniupdate.com/XSL/Variables"
				xmlns:ouc="http://omniupdate.com/XSL/Variables"
				exclude-result-prefixes="xs ou ouc"
				expand-text="no">

	<xsl:import href="/var/staging/OMNI-INF/stylesheets/implementation/v1/template-matches.xsl"/> <!-- global template matches -->
	<xsl:import href="/var/staging/OMNI-INF/stylesheets/implementation/v1/variables.xsl"/> <!-- global variables -->
	<xsl:import href="/var/staging/OMNI-INF/stylesheets/implementation/v1/functions.xsl"/> <!-- global functions -->
	<xsl:import href="../_shared/variables.xsl"/> <!-- customer variables -->
	<xsl:import href="_core/functions.xsl"/> <!-- DMC functions -->

	<xsl:output method="text" />

	<xsl:template match="/document">
		<xsl:variable name="internal-doc" select="ou:get-internal-doc(ou:pcf-param('aggregation-path'))" />


		<!-- Constructing the string with department values -->
		<xsl:variable name="programs">
			<xsl:for-each select="$internal-doc/items/item">
				<xsl:sort select="." />
				<xsl:text>{</xsl:text>
				<xsl:text>"image": "</xsl:text><xsl:value-of select="./image/img/@src"/><xsl:text>",</xsl:text>
				<xsl:text>"title": "</xsl:text><xsl:value-of select="./title"/><xsl:text>",</xsl:text>
				<xsl:text>"area": "</xsl:text><xsl:value-of select="./area"/><xsl:text>",</xsl:text>
				<xsl:text>"classification": "</xsl:text><xsl:value-of select="./classification"/><xsl:text>",</xsl:text>
				<xsl:text>"link": "</xsl:text><xsl:value-of select="./@href"/><xsl:text>"</xsl:text>
				<xsl:text>}</xsl:text>
				<xsl:if test="position() != last()"> 
					<!-- Adding comma between values -->
					<xsl:text>, </xsl:text>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>

		<!-- Constructing the JSON structure -->
		<xsl:variable name="json">
			<xsl:text>[</xsl:text>
			<xsl:value-of select="$programs"/>
			<xsl:text>]</xsl:text>
		</xsl:variable>

		<!-- Serializing the JSON structure -->
		<xsl:value-of select="$json"/>
	</xsl:template>


</xsl:stylesheet>
