XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Kurt MartinSubject: Selecting specific child elements
Author: Kurt Martin
Date: 01 Sep 2006 11:45 AM
I have the following snippet of XML code:

<g id="OBJECT">
<g id="_602" cs:objtype="circle" style="stroke-width:0.00350432;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.25" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<ellipse rx="0.0897105699" ry="0.0897105699" cx="6.04304637" cy="-7.95467306"/>
</g>
<g id="_85B" cs:objtype="point" style="stroke-width:0.00140173;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.1" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<polyline points="6.74875947,-3.29164927 6.74875947,-3.29164927 "/>
</g>
<g id="_85C" cs:objtype="line" style="stroke-width:0.00350432;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.25" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<polyline points="6.67474835,-3.41612189 6.67474835,-3.29164927 "/>
<polyline points="6.63774276,-3.34099005 6.78576508,-3.34099005 "/>
<polyline points="6.63774276,-3.48901208 6.63774276,-3.34099005 "/>
<polyline points="6.78576508,-3.48901208 6.78576508,-3.34099005 "/>
<polyline points="6.74875947,-3.41612189 6.74875947,-3.29164927 "/>
</g>
<g id="_861" cs:objtype="arc" style="stroke-width:0.00350432;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.25" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<path d="M6.78576548,-3.48901208 A0.0740115503,0.0740115503 0 0,0 6.63774238,-3.48901213 "/>
<path d="M6.7487601,-3.41612189 A0.0370061729,0.0370061729 0 0,0 6.67474776,-3.41612191 "/>
</g>
<g id="_868" cs:objtype="point" style="stroke-width:0.00140173;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.1" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<polyline points="9.68308463,-1.55590809 9.68308463,-1.55590809 "/>
</g>
<g id="_86D" cs:objtype="point" style="stroke-width:0.00140173;fill:none;stroke:rgb(0,0,255);" cs:linecolor="rgb(0,0,255)" cs:lineweight="0.1" cs:linestyle="CONTINUOUS" cs:linestylescale="1">
<polyline points="11.7777285,-2.37453136 11.7777285,-2.37453136 "/>
</g>
</g>

I need to copy all of the child elements EXCEPT child g elements, so my output would be:

<g id="OBJECT">

<ellipse rx="0.0897105699" ry="0.0897105699" cx="6.04304637" cy="-7.95467306"/>
<polyline points="6.74875947,-3.29164927 6.74875947,-3.29164927 "/>
<polyline points="6.67474835,-3.41612189 6.67474835,-3.29164927 "/>
<polyline points="6.63774276,-3.34099005 6.78576508,-3.34099005 "/>
<polyline points="6.63774276,-3.48901208 6.63774276,-3.34099005 "/>
<polyline points="6.78576508,-3.48901208 6.78576508,-3.34099005 "/>
<polyline points="6.74875947,-3.41612189 6.74875947,-3.29164927 "/>
<path d="M6.78576548,-3.48901208 A0.0740115503,0.0740115503 0 0,0 6.63774238,-3.48901213 "/>
<path d="M6.7487601,-3.41612189 A0.0370061729,0.0370061729 0 0,0 6.67474776,-3.41612191 "/>
<polyline points="9.68308463,-1.55590809 9.68308463,-1.55590809 "/>
<polyline points="11.7777285,-2.37453136 11.7777285,-2.37453136 "/>

</g>

Any ideas?

Posttop
Tony LavinioSubject: Selecting specific child elements
Author: Tony Lavinio
Date: 11 Sep 2006 04:48 PM
Try something like this:

<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="US-ASCII" indent="yes"/>
<!-- create an encapsulating outer g element -->
<xsl:template match="/">
<g>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*"/>
</g>
</xsl:template>
<!-- eat up the nested 'g' elements -->
<xsl:template match="g">
<xsl:apply-templates select="*"/>
</xsl:template>
<!-- copy everything that isn't matched by the above more-precise rule -->
<xsl:template match="*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.