2017-12-28 51 views
0

: 私のxsdがある:インスタンス文書でxpathを使用して要素をxsdタイプで選択するにはどうすればよいですか?たとえば

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
    <xs:element name="Zoo"> 
     <xs:complexType> 
      <xs:sequence maxOccurs="unbounded"> 
       <xs:element ref="Animal"/> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
    <xs:element abstract="true" name="Animal"/> 
    <xs:element name="Tiger" substitutionGroup="Animal" type="Tiger"/> 
    <xs:element name="Wolf" substitutionGroup="Animal" type="Wolf"/> 
    <xs:complexType name="Animal"> 
     <xs:attribute name="name"/> 
    </xs:complexType> 
    <xs:complexType name="Tiger"> 
     <xs:complexContent> 
      <xs:extension base="Animal"/> 
     </xs:complexContent> 
    </xs:complexType> 
    <xs:complexType name="Wolf"> 
     <xs:complexContent> 
      <xs:extension base="Animal"/> 
     </xs:complexContent> 
    </xs:complexType> 
</xs:schema> 

私のインスタンス文書は、次のとおりです。

<Zoo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Zoo.xsd"> 
    <Tiger name="001"/> 
    <Wolf name="002"/> 
    <Wolf name="003"/> 
</Zoo> 

その複合型動物であるすべての要素を選択するために、XPathを使用する方法は? xpathはxsdメタ情報を使用できますか?スキーマ対応のプロセッサを搭載した

答えて

2

(サクソン9 EEかのAltovaのXMLSpy /ラプターのように)あなたが//element(*, Animal)https://www.w3.org/TR/xpath-31/#doc-xpath31-ElementTest)は、そのタイプAnimalを持つすべての要素を選択するために使用することができ、スタイルシートは、それが動作

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:math="http://www.w3.org/2005/xpath-functions/math" 
    exclude-result-prefixes="xs math" 
    version="3.0"> 

    <xsl:import-schema schema-location="Zoo.xsd"/> 

    <xsl:template match="/"> 
     <xsl:copy-of select="//element(*, Animal)"/> 
    </xsl:template> 

</xsl:stylesheet> 
+0

次のようになります、ありがとう。 – chansey

+0

xpathビルダーがXPath 3.0SAを選択するoxygen xmlエディターで動作しますが、xsltは空のまま戻ります。 – chansey

+0

Saxon EEを使用し、スキーマベースの検証を有効にするために、変換シナリオを設定してください。 –

関連する問題