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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + get the current position as pa... (2)
-> - unable to get Parameter from x... (1)
-> + get key value from xslt to jav... (2)
-> + Xpath insensitive search? (3)
-> + relative path 2 (10)
-> + sum and group attrs, list only... (3)
-> - Simple multiplication.... but ... (1)
-> + .NET issue (2)
-> + Grouping items (9)
-> + Group Move (4)
-> + Problem with DateTime manipula... (2)
-> + xls fo positioning in block (2)
-> + Filtering with XSLT not workin... (3)
-> + Petri net to BPEL model transf... (3)
-> - Selecting specific child eleme... (2)
-> ->Selecting specific child ...
-> + Grouping and summing ... (3)
-> + XSL-FO question: can't get ext... (2)
-> + for each with a parallel nodel... (3)
-> + unable to load schmea with tar... (5)
-> + Translating svg path data to x... (5)
-- Previous [1321-1340] [1341-1360] [1361-1380] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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>

   
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.