这复制了任何名称的第一个不同的simpleType,但使用“NameType”complexType更显式:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="core AcRec"
xmlns:core="foo" xmlns:AcRec="bar">
<xsl:key name="simpleTypes" match="xs:simpleType" use="@name"/>
<xsl:template match="/xs:schema">
<xsl:copy>
<xsl:copy-of select="xs:complexType[@name='NameType'][1]"/>
<xsl:apply-templates />
<xsl:copy-of select="//xs:simpleType[generate-id(.) = generate-id(key('simpleTypes', @name)[1])]" />
</xsl:copy>
</xsl:template>
<xsl:template match="*[name()!='xs:simpleType' and name()!='xs:schema' and @name!='NameType']">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
请注意,默认模板已被覆盖,这样您就不会得到“NameType”的不需要的子级。