qdox/pom-maven2jpp-mapdeps.xsl
2008-10-24 19:44:10 +00:00

83 lines
2.8 KiB
XML

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