2009-07-09 7 views
0

나는 다음과 같은 XSD 니펫을 한 취급 :XSLT : 선택적 노드

<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 다르게 요소 태그를 주석과 XS : 제한 태그를. 내가 가지고있는 것 :

  • xs : element 태그 : 나는 그것을 복사하고 싶다.
  • 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 제외됩니다 : 주석 & XS : 제한 노드를

동안

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