XSLT to transform XSD to another XSD with minOccurs tags

I have an existing XSD with a series of complex types defined in it. I need to build a correlary XSD for each of these types but every element in each of the complex types needs to be optional (minOccurs = "0").

I found this posting as an example to start from ... but I'm not able to add the optional tag. transforming with xsl an xml schema template to an other xml schema template

Any help from someone who is more versed with XSLT than I?


由于您没有提供样本,所以我没有进行过非常多的测试,但以下基于Identity变换的样式表可以成为一项工作。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <!-- Identity transform - copy everything into output -->
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*" />
        </xsl:copy>
    </xsl:template>

    <!-- for not-root xs:element ... -->
    <xsl:template match="xs:element[ancestor::xs:complexType]">
        <xsl:copy>
            <!-- ... add minOccurs element ...-->
            <xsl:attribute name="minOccurs">0</xsl:attribute>
            <!-- ... and copy everything but not minOccurs attribute if any -->
            <xsl:apply-templates select="node() | @*[not(name() = 'minOccurs')]" />     
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
链接地址: http://www.djcxy.com/p/34336.html

上一篇: 与命名空间匹配的XSLT密钥

下一篇: 使用minOccurs标签将XSD转换为另一个XSD的XSLT