2009-07-09 4 views
0

я следующие XSD фрагмент кода:XSLT: Selective Узел Обработка

<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: тег элемента, я хочу его скопировать.
  • xs: групповой тег, я хочу, чтобы на выходе содержались теги тега xs: group tags.
  • Любой другой тег может быть проигнорировано, я не хочу его в моем выходе

Я пытался использовать:

<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: узлы рестрикции, а

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

ответ

0

Изменено:

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