Skip to content

Instantly share code, notes, and snippets.

@staylorx
Forked from ebratb/xsd-merge.xslt
Last active August 29, 2015 14:20
Show Gist options
  • Save staylorx/72212de432bb7ede0aa0 to your computer and use it in GitHub Desktop.
Save staylorx/72212de432bb7ede0aa0 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output version="1.0" encoding="utf-8" indent="yes" name="xml" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="xsd:schema">
<xsl:copy-of select="document(xsd:import/@schemaLocation)" />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output version="1.0" encoding="utf-8" indent="yes" name="xml" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="xsd:import/@schemaLocation" />
<xsl:template match="xsd:import">
<xsl:copy>
<xsl:apply-templates select="@*|node()|processing-instruction()|comment()" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()|processing-instruction()|comment()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output version="1.0" encoding="utf-8" indent="yes" name="xml" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*[namespace-uri()='http://www.w3.org/2001/XMLSchema']">
<xsl:element name="xsd:{local-name()}" namespace="http://www.w3.org/2001/XMLSchema">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output version="1.0" encoding="utf-8" indent="yes" name="xml" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="xsd:schema">
<xsl:variable name="filename" select="concat(replace(replace(@targetNamespace, '^https?://', ''), '[^a-zA-Z0-9_.+-]', '_'), '.xsd')" />
<xsl:result-document href="{$filename}" format="xml">
<xsl:copy-of select="." />
</xsl:result-document>
<xsl:element name="xsd:schema" namespace="http://www.w3.org/2001/XMLSchema">
<xsl:element name="xsd:import">
<xsl:attribute name="namespace">
<xsl:value-of select="@targetNamespace" />
</xsl:attribute>
<xsl:attribute name="schemaLocation">
<xsl:value-of select="$filename" />
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment