我有一个 XSD 文档,我正试图用 XSL 解析以用于文档目的,其中 complexTypes 经常包含其他 complexTypes 的元素。如果可能的话,我想在它们的容器旁边显示这些复杂类型元素的内容。这是我正在使用的一个简单示例:
<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>
我如何让上面的内容显示为:“S 包含 X 类型的 A(包含 F、G 和 H)”?
提前感谢您的帮助!
添加示例:
<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>
</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>