[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Seek an elegant way to remove a sub-tree from an

Subject: Re: Seek an elegant way to remove a sub-tree from an element
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 22 Oct 2011 21:45:31 +0100
Re:  Seek an elegant way to remove a sub-tree from an
Use the modified-identity-transformation pattern:

<xsl:template match="*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>

<xsl:template match="xs:simpleType//xs:simpleType"/>

However, note that your desired output is not a valid XSD document fragment.

Michael Kay
Saxonica

On 22/10/2011 20:19, Costello, Roger L. wrote:
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.