1

complexTypes に他の complexTypes である要素が頻繁に含まれる場合、ドキュメンテーションの目的で XSL を使用して解析しようとしている XSD ドキュメントがあります。可能であれば、これらの複合型要素の内容をコンテナーの横に表示したいと考えています。これが私が取り組んでいることの簡単な例です:

<xs:complexType name="S">
  <xs:sequence>
    <xs:element name="A" type="X"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="X">
  <xs:sequence>
    <xs:element name="F"/>
    <xs:element name="G"/>
    <xs:element name="H"/>
  </xs:sequence>
</xs:complexType>

上記を次のように表示するにはどうすればよいですか?

事前に助けてくれてありがとう!

追加された例:

  <xsl:for-each select="*">
    <xsl:choose>

      <!-- call template without param -->
      <xsl:when test="name() = 'xs:complexType'">
        <xsl:value-of select="@name"/>
        <xsl:text> contains </xsl:text>

        <xsl:call-template name="top"/>
        <xsl:text>&#xa;</xsl:text>
      </xsl:when>

      <!-- for contained elements with types -->
      <xsl:when test="@type != ''  and  name() = 'xs:element' and $typeToLocate = ''">
        <xsl:value-of select="@name"/>
        <xsl:text> of type </xsl:text>
        <xsl:value-of select="@type"/>
        <xsl:text>(which contains: </xsl:text>

        <!--
          point at which i want processor to return to root, locate the
          indicated complex type, output its contents then continue going
          through schema.
        -->
        <xsl:call-template name="top">
          <xsl:with-param name="typeToLocate" select="@type"/>
        </xsl:call-template>

        <xsl:text>)</xsl:text>
      </xsl:when>

      <!-- when type is located, send it to signal proper output -->
      <xsl:when test="$typeToLocate != ''  and  $typeToLocate = @name">
        <xsl:call-template name="top">
          <xsl:with-param name="typeToLocate" select="$typeToLocate"/>
        </xsl:call-template>
      </xsl:when>

      <!-- for elements contained in indicated type -->
      <xsl:when test="$typeToLocate != ''  and  name() = 'xs:element'">
        <xsl:value-of select="@name"/>
        <xsl:text> </xsl:text>

        <xsl:call-template name="top">
          <xsl:with-param name="typeToLocate" select="$typeToLocate"/>
        </xsl:call-template>
      </xsl:when>

      <!-- for continuing through non-content elements under found type -->
      <xsl:when test="$typeToLocate != ''">
        <xsl:call-template name="top">
          <xsl:with-param name="typeToLocate" select="$typeToLocate"/>
        </xsl:call-template>
      </xsl:when>

      <!-- for ignoring non-content elements during normal processing -->
      <xsl:otherwise>
        <xsl:call-template name="top"/>
      </xsl:otherwise>

    </xsl:choose>
  </xsl:for-each>

</xsl:template>
4

1 に答える 1

0

特定のスタイルシートを提供せずに、あなたの質問に広く答えるために、私は提案します...

(1)XSDパブリックレベルで複合型に一致するテンプレートを作成します。上記のテンプレートのシーケンスコンストラクターは、「S」のようなテキストの生成を直接担当します。

(2)上記のシーケンスコンストラクター内で、上記のテキスト生成後、複合型ノードで呼び出します。これは、「含む...」から始まる、目的の残りのプロダクションを担当します。

(3)describe-contentsテンプレートを作成します。ここでのシーケンスコンストラクタは、次の2つの部分で構成されます。(3.1)「含む」のような一定の生成。(3.2)シーケンスメンバーのapply-templatesの呼び出し。この部分は「タイプX(which〜)のA」のように生成されます

(4)xs:sequence / xs:elementに一致するテンプレートを作成します。3.2から推測できるように、シーケンスコンストラクターは次の3つの部分で構成されます。そして最後に(4.3)「)」の絶え間ない生成

目標がxs:sequenceおよび複合型に限定されている場合は、これで十分です。それにもかかわらず、テンプレートが構文要素にほぼ一致するこのテンプレートベースのアプローチは、xs:choiceなどに拡張可能である必要があります。

ディープレベルの複合型定義の再帰的な記述が実際に必要であると想定しました。

于 2012-05-14T05:38:49.717 に答える