XSLT:选择性节点处理

XSLT:选择性节点处理,xslt,Xslt,我有以下xsd代码段: <xs:complexType name="HighSchoolType"> <xs:sequence> <xs:element name="OrganizationName" type="core:OrganizationNameType"/> <xs:group ref="core:OrganizationIDGroup" minOccurs="0"/> </xs:sequence&

我有以下xsd代码段:

<xs:complexType name="HighSchoolType">
  <xs:sequence>
      <xs:element name="OrganizationName" type="core:OrganizationNameType"/>
      <xs:group ref="core:OrganizationIDGroup" minOccurs="0"/>
  </xs:sequence>
</xs:complexType>

我希望以不同于xs:group标记的方式处理xs:element标记,同时完全忽略xs:annotation和xs:restriction标记。当我有一个

  • 元素标记,我想复制它
  • xs:group标记,我希望输出包含xs:group标记的子项
  • 任何其他标记都可以忽略,我不希望它出现在我的输出中
我一直在尝试使用:

<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>

我不明白为什么会这样:

<xsl:copy-of select="*[not(self::xs:annotation or self::xs:restriction)]|@*"/>

…将排除xs:annotation&xs:restriction节点,同时

<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: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> 

已更改:

<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>

…分为:

<xsl:template match="xs:complexType">
  <xsl:copy>
    <xsl:for-each select="@*">
      <xsl:copy />
    </xsl:for-each>
    <xsl:apply-templates select="node()" />
  </xsl:copy>
</xsl:template>

<xsl:template match="xs:sequence">
  <xsl:copy>
    <xsl:for-each select="node()">
      <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:for-each>
  </xsl:copy>
</xsl:template>