I have the following xsd snippet:
<xs:complexType name="HighSchoolType">
<xs:sequence>
<xs:element name="OrganizationName" type="core:OrganizationNameType"/>
<xs:group ref="core:OrganizationIDGroup" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
I want to handle xs:element tags differently than xs:group tags, while completely ignoring xs:annotation and xs:restriction tags. When I have an:
- xs:element tag, I want to copy it.
- xs:group tag, I want the output to contain the children of the xs:group tags' tag.
- Any other tag can be ignored, I don't want it in my output
I've been trying to use:
<xsl:template match="xs:complexType">
<xsl:copy>
<xsl:choose>
<xsl:when test="*[self::xs:element]|@*">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="*[self::xs:group]|@*">
<xsl:apply-templates select="."/>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
I don't understand why this:
<xsl:copy-of select="*[not(self::xs:annotation or self::xs:restriction)]|@*"/>
...will exclude xs:annotation & xs:restriction nodes while
<xsl:when test="*[self::xs:element]|@*">
<xsl:copy-of select="."/>
</xsl:when>
...returns everything while:
<xsl:when test="*[self::xs:group]|@*">
<xsl:apply-templates select="."/>
</xsl:when>
...never triggers:
<xsl:variable name="core" select="document('CoreMain_v1.4.0.xsd')" />
<xsl:variable name="AcRec" select="document('AcademicRecord_v1.3.0.xsd')" />
<xsl:template match="xs:group[@ref]">
<xsl:variable name="name" select="substring-after(@ref, ':')" />
<xsl:choose>
<xsl:when test="substring-before(@ref, ':') = 'AcRec'">
<xsl:apply-templates select="$AcRec//*[@name=$name]" />
</xsl:when>
<xsl:when test="substring-before(@ref, ':') = 'core'">
<xsl:apply-templates select="$core//*[@name=$name]" />
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="xs:group[@name]">
<xsl:copy-of select="node()[not(self::xs:annotation|self::xs:restriction)]|@*"/>
</xsl:template>