I have a XML file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:stuff>
<xs:nestedStuff name="nested"/>
</xs:stuff>
<xs:simpleType name="A_B">
<xs:union memberTypes="xs:A xs:B"/>
</xs:simpleType>
<xs:simpleType name="A_B_C">
<xs:union memberTypes="xs:A xs:B xs:C"/>
</xs:simpleType>
<xs:simpleType name="A_B">
<xs:union memberTypes="xs:A xs:B"/>
</xs:simpleType>
<xs:simpleType name="A_B">
<xs:union memberTypes="xs:A xs:B"/>
</xs:simpleType>
<xs:simpleType name="A_B_C">
<xs:union memberTypes="xs:A xs:B xs:C"/>
</xs:simpleType>
<xs:simpleType name="A_C">
<xs:union memberTypes="xs:A xs:C"/>
</xs:simpleType>
</xs:schema>
What I want to do is copy every single line of this file except for the duplicate simpleType
elements, so that I would get
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:stuff>
<xs:nestedStuff name="nested"/>
</xs:stuff>
<xs:simpleType name="A_B">
<xs:union memberTypes="xs:A xs:B"/>
</xs:simpleType>
<xs:simpleType name="A_B_C">
<xs:union memberTypes="xs:A xs:B xs:C"/>
</xs:simpleType>
<xs:simpleType name="A_C">
<xs:union memberTypes="xs:A xs:C"/>
</xs:simpleType>
</xs:schema>
I cannot use XLST-2.0. I am very new to XSLT, and I have tried various things from here, but it does not apply to my problem the way I thought it did. Here is an example of what I tried, and that results in an output exactly equal to the input:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:for-each select="simpleType/@name[not(.=preceding::*)]">
<xsl:element name="xs:TEST">
</xsl:element>
</xsl:for-each>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>