Matt Wringe 08dabf2
Matt Wringe 08dabf2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Matt Wringe 08dabf2
 <xsl:param name="map" /> 
Matt Wringe 08dabf2
 <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> 
Matt Wringe 08dabf2
 <xsl:strip-space elements="*"/> 
Matt Wringe 08dabf2
 <xsl:template match="/project" >
Matt Wringe 08dabf2
  <xsl:element name="project">
Matt Wringe 08dabf2
   <xsl:copy-of select="child::*[not(self::dependencies)]"/>
Matt Wringe 08dabf2
   <xsl:if test="not(./dependencies)">
Matt Wringe 08dabf2
    <xsl:element name="dependencies">
Matt Wringe 08dabf2
     <xsl:for-each select="document($map)//add/dependency">
Matt Wringe 08dabf2
       <xsl:copy-of select="."/>
Matt Wringe 08dabf2
     </xsl:for-each>
Matt Wringe 08dabf2
    </xsl:element>
Matt Wringe 08dabf2
   </xsl:if>
Matt Wringe 08dabf2
   <xsl:apply-templates select="dependencies"/>
Matt Wringe 08dabf2
  </xsl:element>
Matt Wringe 08dabf2
 </xsl:template>
Matt Wringe 08dabf2
 <xsl:template match="dependencies" >
Matt Wringe 08dabf2
  <xsl:element name="dependencies">
Matt Wringe 08dabf2
   <xsl:for-each select="dependency">
Matt Wringe 08dabf2
    <xsl:if test="./artifactId">
Matt Wringe 08dabf2
     <xsl:call-template name="replace">
Matt Wringe 08dabf2
      <xsl:with-param name="artifact" select="./artifactId/text()"/>
Matt Wringe 08dabf2
     </xsl:call-template>
Matt Wringe 08dabf2
    </xsl:if>
Matt Wringe 08dabf2
    <xsl:if test="./id">
Matt Wringe 08dabf2
     <xsl:choose>
Matt Wringe 08dabf2
      <xsl:when test="substring-after(./id/text(),':') != ''">
Matt Wringe 08dabf2
       <xsl:call-template name="replace">
Matt Wringe 08dabf2
        <xsl:with-param name="artifact" select="substring-after(./id/text(),':')"/>
Matt Wringe 08dabf2
       </xsl:call-template>
Matt Wringe 08dabf2
      </xsl:when>
Matt Wringe 08dabf2
      <xsl:otherwise>
Matt Wringe 08dabf2
       <xsl:call-template name="replace">
Matt Wringe 08dabf2
        <xsl:with-param name="artifact" select="./id/text()"/>
Matt Wringe 08dabf2
       </xsl:call-template>
Matt Wringe 08dabf2
      </xsl:otherwise>
Matt Wringe 08dabf2
     </xsl:choose>
Matt Wringe 08dabf2
    </xsl:if>
Matt Wringe 08dabf2
   </xsl:for-each>
Matt Wringe 08dabf2
   <xsl:for-each select="document($map)//add/dependency">
Matt Wringe 08dabf2
    <xsl:copy-of select="."/>
Matt Wringe 08dabf2
   </xsl:for-each>
Matt Wringe 08dabf2
  </xsl:element>
Matt Wringe 08dabf2
 </xsl:template>
Matt Wringe 08dabf2
 <xsl:template name="replace">
Matt Wringe 08dabf2
  <xsl:param name="artifact"/>
Matt Wringe 08dabf2
  <xsl:variable name="this" select="."/>
Matt Wringe 08dabf2
  <xsl:element name="dependency">
Matt Wringe 08dabf2
   <xsl:choose>
Matt Wringe 08dabf2
    <xsl:when test="document($map)//dependency/maven[./artifactId/text() = $artifact]">
Matt Wringe 08dabf2
     <xsl:for-each select="document($map)//dependency/maven[./artifactId/text() = $artifact][1]">
Matt Wringe 08dabf2
      <xsl:copy-of select="../jpp/*"/>
Matt Wringe 08dabf2
      <xsl:copy-of select="$this/properties"/>
Matt Wringe 08dabf2
     </xsl:for-each>
Matt Wringe 08dabf2
    </xsl:when>
Matt Wringe 08dabf2
    <xsl:otherwise>
Matt Wringe 08dabf2
     <xsl:copy-of select="./*"/>
Matt Wringe 08dabf2
    </xsl:otherwise>
Matt Wringe 08dabf2
   </xsl:choose>
Matt Wringe 08dabf2
  </xsl:element>
Matt Wringe 08dabf2
  <xsl:if test="document($map)//dependency/maven[./artifactId/text() = $artifact]">
Matt Wringe 08dabf2
   <xsl:for-each select="document($map)//dependency/maven[./artifactId/text() = $artifact][1]">
Matt Wringe 08dabf2
    <xsl:for-each select="../add/dependency">
Matt Wringe 08dabf2
     <xsl:element name="dependency">
Matt Wringe 08dabf2
      <xsl:copy-of select="./*"/>
Matt Wringe 08dabf2
      <xsl:copy-of select="$this/properties"/>
Matt Wringe 08dabf2
     </xsl:element>
Matt Wringe 08dabf2
    </xsl:for-each>
Matt Wringe 08dabf2
   </xsl:for-each>
Matt Wringe 08dabf2
  </xsl:if>
Matt Wringe 08dabf2
 </xsl:template>
Matt Wringe 08dabf2
</xsl:stylesheet>