xsl-list
[Top] [All Lists]

[xsl] Seek an elegant way to remove a sub-tree from an element

2011-10-22 14:37:59
Hi Folks,

This simpleType element contains within it another simpleType element:

<xs:simpleType name="BostonAreaElevation">
        <xs:restriction>
                <xs:simpleType>
                        <xs:restriction base="xs:int">
                                <xs:minInclusive value="-1290" />
                                <xs:maxInclusive value="29035" />
                        </xs:restriction>
                </xs:simpleType>
                <xs:minInclusive value="0" />
                <xs:maxInclusive value="120" />
        </xs:restriction>
</xs:simpleType>

I want to remove the inner simpleType, thus producing:

<xs:simpleType name="BostonAreaElevation">
        <xs:restriction>
                <xs:minInclusive value="0" />
                <xs:maxInclusive value="120" />
        </xs:restriction>
</xs:simpleType>

I seek an elegant way to accomplish this.

The following is one way to accomplish it. Is there a more elegant way to 
accomplish it?

<xsl:variable name="outer-simpleType">
        <xsl:element name="simpleType" namespace="{namespace-uri($simpleType)}">
                <xsl:copy-of select="$simpleType/namespace::*" />
                <xsl:for-each select="$simpleType/@*">
                        <xsl:attribute name="{name(.)}"><xsl:value-of 
select="." /></xsl:attribute>
                </xsl:for-each>
                <xsl:element name="restriction" 
namespace="{namespace-uri(simpleType/xs:restriction)}">
                        <xsl:copy-of 
select="$simpleType/xs:restriction/namespace::*" />
                        <xsl:for-each select="$simpleType/xs:restriction/@*">
                                <xsl:attribute name="{name(.)}"><xsl:value-of 
select="." /></xsl:attribute>
                        </xsl:for-each>
                        <xsl:sequence 
select="$simpleType/xs:restriction/xs:*[not(self::xs:simpleType)]" />
                </xsl:element>
        </xsl:element>
</xsl:variable>

/Roger

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>