f837e3e
f837e3e
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
f837e3e
  <xsl:param name="map" /> 
f837e3e
  <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> 
f837e3e
  <xsl:strip-space elements="*"/> 
f837e3e
  <xsl:template match="/*[name()='project']" >
f837e3e
	<xsl:element name="project">
f837e3e
f837e3e
	  
f837e3e
f837e3e
	  <xsl:variable name="artifact" select="./*[name()='artifactId']"/>
f837e3e
	  <xsl:variable name="group" select="./*[name()='groupId']"/>
f837e3e
	  <xsl:variable name="parentGroup" select="./*[name()='parent']/*[name()='groupId']"/>
f837e3e
f837e3e
	  <xsl:choose>
f837e3e
		<xsl:when test="(document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)])">
f837e3e
		  <xsl:for-each select="document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)][1]">
f837e3e
			<xsl:if test="../jpp">
f837e3e
			  <xsl:copy-of select="../jpp/*"/>
f837e3e
			</xsl:if>
f837e3e
		  </xsl:for-each>
f837e3e
		</xsl:when>
f837e3e
f837e3e
		<xsl:otherwise>
f837e3e
		  <xsl:choose>
f837e3e
f837e3e
			
f837e3e
			<xsl:when test="(document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $parentGroup)])">
f837e3e
			  <xsl:for-each select="document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $parentGroup)][1]">
f837e3e
				<xsl:if test="../jpp">
f837e3e
				  <xsl:copy-of select="../jpp/*"/>
f837e3e
				</xsl:if>
f837e3e
			  </xsl:for-each>
f837e3e
			</xsl:when>
f837e3e
f837e3e
			
f837e3e
			<xsl:otherwise>
f837e3e
			  <xsl:copy-of select="*[name() = 'artifactId']"/>
f837e3e
			  <xsl:copy-of select="*[name() = 'groupId']"/>
f837e3e
			  <xsl:copy-of select="*[name() = 'id']"/>
f837e3e
			  <xsl:copy-of select="*[name() = 'version']"/>
f837e3e
			</xsl:otherwise>
f837e3e
		  </xsl:choose>
f837e3e
		</xsl:otherwise>
f837e3e
	  </xsl:choose>
f837e3e
f837e3e
	  
f837e3e
f837e3e
	  <xsl:for-each select="./*[name()='parent']">
f837e3e
		<xsl:apply-templates select="."/>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	  
f837e3e
	  <xsl:for-each select="./*">
f837e3e
		<xsl:if test="(name() != 'dependencies') and (name() != 'dependencyManagement') and (name() != 'modelVersion') and (name() != 'parent') and (name() != 'build') and (name() != 'profiles') and (name() != 'artifactId') and (name() != 'groupId') and (name() != 'id') and (name() != 'version')">
f837e3e
		  <xsl:copy-of select="." />
f837e3e
		</xsl:if>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	
f837e3e
	  <xsl:if test="not(./*[name()='dependencies'])">
f837e3e
		<xsl:element name="dependencies">
f837e3e
		  <xsl:for-each select="document($map)//add/dependency">
f837e3e
			<xsl:copy-of select="." />
f837e3e
		  </xsl:for-each>
f837e3e
		</xsl:element>
f837e3e
	  </xsl:if>
f837e3e
f837e3e
	  
f837e3e
	       "<modelVersion>4.0.0" which fails if the line below is
f837e3e
	       removed (because without it, the ns attribute would be
f837e3e
	       added to the modelVersion tag) -->
f837e3e
f837e3e
	  <xsl:for-each select="./*[name()='modelVersion']">
f837e3e
		<xsl:element name="{name()}">
f837e3e
		  <xsl:value-of select="text()" />
f837e3e
		</xsl:element>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	  
f837e3e
	  <xsl:apply-templates select="*[name()='build']"/>
f837e3e
	  <xsl:apply-templates select="*[name()='profiles']"/>
f837e3e
	  <xsl:apply-templates select="*[name()='dependencies']"/>
f837e3e
	  <xsl:element name="dependencyManagement">
f837e3e
		<xsl:for-each select="*[name()='dependencyManagement']">
f837e3e
		  <xsl:apply-templates select="*[name()='dependencies']"/>
f837e3e
		</xsl:for-each>
f837e3e
	  </xsl:element>
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template match="*[name()='dependencies']">
f837e3e
	<xsl:element name="dependencies">
f837e3e
	  <xsl:for-each select="*[name()='dependency']">
f837e3e
		<xsl:if test="*[name()='artifactId']">
f837e3e
		  <xsl:call-template name="replace">
f837e3e
			<xsl:with-param name="artifact" select="*[name()='artifactId']/text()"/>
f837e3e
			<xsl:with-param name="group" select="*[name()='groupId']/text()"/>
f837e3e
		  </xsl:call-template>
f837e3e
		</xsl:if>
f837e3e
		<xsl:if test="*[name()='id']">
f837e3e
		  <xsl:choose>
f837e3e
			<xsl:when test="substring-after(*[name()='id']/text(),':') != ''">
f837e3e
			  <xsl:call-template name="replace">
f837e3e
				<xsl:with-param name="artifact" select="substring-after(*[name()='id']/text(),':')"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:when>
f837e3e
			<xsl:otherwise>
f837e3e
			  <xsl:call-template name="replace">
f837e3e
				<xsl:with-param name="artifact" select="*[name()='id']/text()"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:otherwise>
f837e3e
		  </xsl:choose>
f837e3e
		</xsl:if>
f837e3e
	  </xsl:for-each>
f837e3e
	  <xsl:for-each select="document($map)//add/dependency">
f837e3e
		<xsl:copy-of select="."/>
f837e3e
	  </xsl:for-each>
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
f837e3e
  <xsl:template name="replace">
f837e3e
	<xsl:param name="artifact"/>
f837e3e
	<xsl:param name="group"/>
f837e3e
	<xsl:variable name="this" select="."/>
f837e3e
	  <xsl:choose>
f837e3e
		<xsl:when test="(document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)])">
f837e3e
		  <xsl:for-each select="document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)][1]">
f837e3e
			<xsl:if test="../jpp">
f837e3e
			  <xsl:element name="dependency">
f837e3e
				<xsl:copy-of select="../jpp/*"/>
f837e3e
				<xsl:for-each select="$this/*">
f837e3e
				  <xsl:if test="(name() != 'groupId') and (name() != 'artifactId') and (name() != 'id') and (name() != 'version')">
f837e3e
					<xsl:copy-of select="."/>
f837e3e
				  </xsl:if>
f837e3e
				</xsl:for-each>
f837e3e
			  </xsl:element>
f837e3e
			</xsl:if>
f837e3e
		  </xsl:for-each>
f837e3e
		</xsl:when>
f837e3e
		<xsl:otherwise>
f837e3e
		  <xsl:element name="dependency">
f837e3e
			<xsl:copy-of select="./*"/>
f837e3e
		  </xsl:element>
f837e3e
		</xsl:otherwise>
f837e3e
	  </xsl:choose>
f837e3e
	<xsl:if test="document($map)//dependency/maven[./artifactId/text() = $artifact]">
f837e3e
	  <xsl:for-each select="document($map)//dependency/maven[./artifactId/text() = $artifact][1]">
f837e3e
		<xsl:for-each select="../add/dependency">
f837e3e
		  <xsl:element name="dependency">
f837e3e
			<xsl:copy-of select="./*"/>
f837e3e
		  </xsl:element>
f837e3e
		</xsl:for-each>
f837e3e
	  </xsl:for-each>
f837e3e
	</xsl:if>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
f837e3e
  <xsl:template match="*[name()='parent']">
f837e3e
	<xsl:element name="parent">
f837e3e
	  <xsl:for-each select=".">
f837e3e
		<xsl:if test="*[name()='artifactId']">
f837e3e
		  <xsl:call-template name="replaceNonDep">
f837e3e
			<xsl:with-param name="artifact" select="*[name()='artifactId']/text()"/>
f837e3e
			<xsl:with-param name="group" select="*[name()='groupId']/text()"/>
f837e3e
		  </xsl:call-template>
f837e3e
		</xsl:if>
f837e3e
		<xsl:if test="*[name()='id']">
f837e3e
		  <xsl:choose>
f837e3e
			<xsl:when test="substring-after(*[name()='id']/text(),':') != ''">
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="substring-after(*[name()='id']/text(),':')"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:when>
f837e3e
			<xsl:otherwise>
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="*[name()='id']/text()"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:otherwise>
f837e3e
		  </xsl:choose>
f837e3e
		</xsl:if>
f837e3e
	  </xsl:for-each>
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template match="*[name()='build']">
f837e3e
	<xsl:element name="build">
f837e3e
	  <xsl:for-each select="./*">
f837e3e
		<xsl:choose>
f837e3e
		  <xsl:when test="(name() != 'plugins') and (name() != 'extensions')">
f837e3e
			<xsl:copy-of select="." />
f837e3e
		  </xsl:when>
f837e3e
		  <xsl:otherwise>
f837e3e
			<xsl:apply-templates select="."/>
f837e3e
		  </xsl:otherwise>
f837e3e
		</xsl:choose>
f837e3e
	  </xsl:for-each>
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template match="*[name()='profiles']">
f837e3e
	<xsl:element name="profiles">
f837e3e
	  <xsl:for-each select="./*">
f837e3e
		<xsl:choose>
f837e3e
		  <xsl:when test="name() != 'profile'">
f837e3e
			<xsl:copy-of select="." />
f837e3e
		  </xsl:when>
f837e3e
		  <xsl:otherwise>
f837e3e
			<xsl:element name="profile">
f837e3e
			  <xsl:for-each select="./*">
f837e3e
				<xsl:choose>
f837e3e
				  <xsl:when test="name() != 'build'">
f837e3e
					<xsl:copy-of select="." />
f837e3e
				  </xsl:when>
f837e3e
				  <xsl:otherwise>
f837e3e
					<xsl:apply-templates select="."/>
f837e3e
				  </xsl:otherwise>
f837e3e
				</xsl:choose>
f837e3e
			  </xsl:for-each>
f837e3e
			</xsl:element>
f837e3e
		  </xsl:otherwise>
f837e3e
		</xsl:choose>
f837e3e
	  </xsl:for-each>
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template match="*[name()='plugins']">
f837e3e
	<xsl:element name="plugins">
f837e3e
	  <xsl:for-each select="*[name()='plugin']">
f837e3e
		<xsl:element name="plugin">
f837e3e
		<xsl:if test="*[name()='artifactId']">
f837e3e
		  <xsl:call-template name="replaceNonDep">
f837e3e
			<xsl:with-param name="artifact" select="*[name()='artifactId']/text()"/>
f837e3e
			<xsl:with-param name="group" select="*[name()='groupId']/text()"/>
f837e3e
		  </xsl:call-template>
f837e3e
		</xsl:if>
f837e3e
		<xsl:if test="*[name()='id']">
f837e3e
		  <xsl:choose>
f837e3e
			<xsl:when test="substring-after(*[name()='id']/text(),':') != ''">
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="substring-after(*[name()='id']/text(),':')"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:when>
f837e3e
			<xsl:otherwise>
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="*[name()='id']/text()"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:otherwise>
f837e3e
		  </xsl:choose>
f837e3e
		</xsl:if>
f837e3e
		</xsl:element>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	  <xsl:for-each select="*[name()!='plugin']">
f837e3e
		<xsl:copy-of select="."/>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template match="*[name()='extensions']">
f837e3e
	<xsl:element name="extensions">
f837e3e
	  <xsl:for-each select="*[name()='extension']">
f837e3e
		<xsl:element name="extension">
f837e3e
		<xsl:if test="*[name()='artifactId']">
f837e3e
		  <xsl:call-template name="replaceNonDep">
f837e3e
			<xsl:with-param name="artifact" select="*[name()='artifactId']/text()"/>
f837e3e
			<xsl:with-param name="group" select="*[name()='groupId']/text()"/>
f837e3e
		  </xsl:call-template>
f837e3e
		</xsl:if>
f837e3e
		<xsl:if test="*[name()='id']">
f837e3e
		  <xsl:choose>
f837e3e
			<xsl:when test="substring-after(*[name()='id']/text(),':') != ''">
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="substring-after(*[name()='id']/text(),':')"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:when>
f837e3e
			<xsl:otherwise>
f837e3e
			  <xsl:call-template name="replaceNonDep">
f837e3e
				<xsl:with-param name="artifact" select="*[name()='id']/text()"/>
f837e3e
			  </xsl:call-template>
f837e3e
			</xsl:otherwise>
f837e3e
		  </xsl:choose>
f837e3e
		</xsl:if>
f837e3e
		</xsl:element>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	  <xsl:for-each select="*[name()!='extension']">
f837e3e
		<xsl:copy-of select="."/>
f837e3e
	  </xsl:for-each>
f837e3e
f837e3e
	</xsl:element>
f837e3e
  </xsl:template>
f837e3e
f837e3e
  
f837e3e
  <xsl:template name="replaceNonDep">
f837e3e
	<xsl:param name="artifact"/>
f837e3e
	<xsl:param name="group"/>
f837e3e
	<xsl:variable name="this" select="."/>
f837e3e
	  <xsl:choose>
f837e3e
		<xsl:when test="(document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)])">
f837e3e
		  <xsl:for-each select="document($map)//dependency/maven[(./artifactId/text() = $artifact) and (./groupId/text() = $group)][1]">
f837e3e
			<xsl:if test="../jpp">
f837e3e
			  <xsl:copy-of select="../jpp/*"/>
f837e3e
			  <xsl:for-each select="$this/*">
f837e3e
				<xsl:if test="(name() != 'groupId') and (name() != 'artifactId') and (name() != 'id') and (name() != 'version')">
f837e3e
				  <xsl:copy-of select="."/>
f837e3e
				</xsl:if>
f837e3e
			  </xsl:for-each>
f837e3e
			</xsl:if>
f837e3e
		  </xsl:for-each>
f837e3e
		</xsl:when>
f837e3e
		<xsl:otherwise>
f837e3e
		  <xsl:copy-of select="./*"/>
f837e3e
		</xsl:otherwise>
f837e3e
	  </xsl:choose>
f837e3e
  </xsl:template>
f837e3e
f837e3e
f837e3e
</xsl:stylesheet>