Skip to content

Instantly share code, notes, and snippets.

@nabsha
Last active October 27, 2018 09:39
Show Gist options
  • Save nabsha/b0d569127379fcc0aebb3d1cb73c0739 to your computer and use it in GitHub Desktop.
Save nabsha/b0d569127379fcc0aebb3d1cb73c0739 to your computer and use it in GitHub Desktop.
replace/merge/combine mule sub-flow and flow in-place of flow-ref
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.mulesoft.org/schema/mule/core">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns0:mule/ns0:sub-flow"/>
<xsl:template match="/ns0:mule/ns0:flow">
<xsl:variable name="flowName" select="current()/@name"/>
<xsl:if test="not(//ns0:flow-ref[@name=$flowName])">
<xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="//ns0:flow-ref">
<xsl:variable name="flowName" select="current()/@name"/>
<xsl:choose>
<xsl:when test="/ns0:mule/ns0:sub-flow[@name=$flowName]">
<xsl:apply-templates select="/ns0:mule/ns0:sub-flow[@name=$flowName]/*"/>
</xsl:when>
<xsl:when test="/ns0:mule/ns0:flow[@name=$flowName]">
<xsl:apply-templates select="/ns0:mule/ns0:flow[@name=$flowName]/*"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment