Using this file as source, I have a situation where I need to retrieve an element from either the local source file or a related one noted in the imports. The type value uses a colon to separate the two values - substring-before(@type, ':') tells me which file to reference; substring-after(@type, ':') is the name of the element in the file I need to copy & iterate over its contents in the same fashion.
Example: I want the xs:complexType where the name is "PersonType", so I use the copy-of to grab it and its children. The next step is to look at those children - for those that are xs:element, I want to retrieve the element referenced in the type value ("AcRec:HighSchoolType"). The "AcRec" tells me which xsd I need to use, so I know I'll find something in that xsd where the name value is "HighSchoolType". Looking at the AcRec xsd, I know that "HighSchoolType" is an xs:complexType (which I already have a template defined to handle) so I should see the output.
<?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">
<xsl:template match="/">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="urn:org:pesc:core:CoreMain:v1.2.0" xmlns:AcRec="urn:org:pesc:sector:AcademicRecord:v1.1.0">
<xsl:apply-templates select="//xs:complexType[@name='PersonType']" />
</xs:schema>
</xsl:template>
<xsl:template match="xs:complexType">
<xsl:copy>
<xsl:copy-of select="node()[not(xs:annotation | xs:restriction)]|@*"/>
</xsl:copy>
<xsl:apply-templates select=".//xs:element" />
</xsl:template>
<xsl:template match="xs:simpleType">
<xsl:copy>
<xsl:copy-of select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element">
<xsl:choose>
<xsl:when test="substring-before(@type, ':') = 'AcRec'">
<xsl:text>AcRec</xsl:text>
<xsl:apply-templates select="document('[local file path]AcademicRecord_v1.3.0.xsd')//*[@name=substring-after(@type, ':')]" />
</xsl:when>
</xsl:choose>
</xsl:template>
Desired output would look like:
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="HighSchool" type="AcRec:HighSchoolType" minOccurs="0">
</xs:sequence>
</xs:complexType>
<xs:complexType name="HighSchoolType">
<xs:sequence>
<xs:element name="OrganizationName" type="core:OrganizationNameType"/>
<xs:group ref="core:OrganizationIDGroup" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
What am I missing about looking within the document when I successfully enter the xsl:when? The xsl:text tells me I'm in, but the subsequent line returns no output.
Additionally, how do I exclude xs:annotation and xs:restriction elements from appearing when copying the xs:complextType & xs:simpleType elements? I haven't been able to get the examples mentioned on the dpawson site to work.