|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
xmlns:oclX="http://eXolutio.com/oclX/functional"
|
|
xmlns:oclXin="http://eXolutio.com/oclX/functional/internal"
|
|
xmlns:const="http://eXolutio.com/oclX/types/constructors"
|
|
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
version="3.0">
|
|
|
|
<xsl:output indent="yes"/>
|
|
|
|
<xsl:template match="/organization">
|
|
<xsl:variable name="employee-new-values"
|
|
select="
|
|
let $projects := //project return
|
|
let $emps := $projects/employee return
|
|
oclX:collect(
|
|
$emps,
|
|
function($e)
|
|
{
|
|
const:TOP-Organization-Employee-CONST(
|
|
'employee',
|
|
data($e/empNo),
|
|
data($e/firstName),
|
|
data($e/lastName),
|
|
$projects)
|
|
}
|
|
)
|
|
"
|
|
as="item()*"/>
|
|
<xsl:copy-of select="$employee-new-values"/>
|
|
</xsl:template>
|
|
|
|
<xsl:function name="const:TOP-Organization-Employee-CONST" as="item()*">
|
|
<xsl:param name="element-name" as="xs:string"/>
|
|
<xsl:param name="empNo" as="xs:string"/>
|
|
<xsl:param name="firstName" as="item()*"/>
|
|
<xsl:param name="lastName" as="item()*"/>
|
|
<xsl:param name="project" as="item()*"/>
|
|
<xsl:choose>
|
|
<xsl:when test="$element-name ne ''">
|
|
<xsl:element name="{$element-name}">
|
|
<xsl:attribute name="empNo" select="$empNo"/>
|
|
<xsl:element name="firstName">
|
|
<xsl:sequence select="$firstName"/>
|
|
</xsl:element>
|
|
<xsl:element name="lastName">
|
|
<xsl:sequence select="$lastName"/>
|
|
</xsl:element>
|
|
<xsl:sequence select="$project"/>
|
|
</xsl:element>
|
|
</xsl:when>
|
|
<xsl:otherwise>
|
|
<xsl:attribute name="empNo" select="$empNo"/>
|
|
<xsl:element name="firstName">
|
|
<xsl:sequence select="$firstName"/>
|
|
</xsl:element>
|
|
<xsl:element name="lastName">
|
|
<xsl:sequence select="$lastName"/>
|
|
</xsl:element>
|
|
<xsl:sequence select="$project"/>
|
|
</xsl:otherwise>
|
|
</xsl:choose>
|
|
</xsl:function>
|
|
|
|
<xsl:function name="oclX:collect" as="item()*">
|
|
<xsl:param name="collection" as="item()*"/>
|
|
<xsl:param name="body" as="function(item()) as item()*"/>
|
|
<xsl:sequence
|
|
select="oclX:iterate($collection, (),
|
|
function($it, $acc) { $acc, $body($it) }
|
|
)"
|
|
/>
|
|
</xsl:function>
|
|
|
|
<xsl:function name="oclX:iterate" as="item()*">
|
|
<xsl:param name="collection" as="item()*"/>
|
|
<xsl:param name="accInit" as="item()*"/>
|
|
<xsl:param name="body" as="function(item(), item()*) as item()*"/>
|
|
|
|
<xsl:iterate select="1 to count($collection)">
|
|
<xsl:param name="acc" select="$accInit" as="item()*"/>
|
|
<xsl:next-iteration>
|
|
<xsl:with-param name="acc" select="$body($collection[current()], $acc)"/>
|
|
</xsl:next-iteration>
|
|
<xsl:on-completion>
|
|
<xsl:sequence select="$acc"/>
|
|
</xsl:on-completion>
|
|
</xsl:iterate>
|
|
</xsl:function>
|
|
|
|
</xsl:stylesheet>
|