Subject: RE: [xsl] Selection of Just Attribute Nodes and Element Child Nodes From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Mon, 28 Jun 2004 03:14:13 -0600 |
You can use a union to select just the attributes with on statement and just the children with another... <newNode> <xsl:copy-of select="foo/barChild/@* | foo/barChild/*"/> </newNode> Would give you: <newNode at="2" anAt="3"> <barGC> ... </barGC> </newNode> Which may very well be enough for you. But depending on what you are trying to do with the results of your XPath statement you may want to do something like: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <newNode> <attributes> <xsl:apply-templates select="foo/barChild/@*"/> </attributes> <children> <xsl:apply-templates select="foo/barChild/*"/> </children> </newNode> </xsl:template> <xsl:template match="@*"> <attribute name="{local-name()}"/> </xsl:template> <xsl:template match="*"> <child name="{local-name()}"/> </xsl:template> </xsl:stylesheet> Which returns... <?xml version="1.0" encoding="UTF-8"?> <newNode> <attributes> <attribute name="at"/> <attribute name="anAt"/> </attributes> <children> <child name="barGC"/> </children> </newNode> Obviously the first is much easier but your options on what you can do with it are limited. The second allows complete control over your output by allowing you to match either all attributes and all children with @* and * as the match attributes value or each individual attribute or child by using their local-name as the match attribute value e.g. match="@at" or match="barGC". Best of luck! <M:D/> :: Announcing Saxon.NET (v.8.0-B) Java to C# and .NET Conversion Project :: :: Be part of the project development at http://www.x2x2x.org/x2x2x/home :: > -----Original Message----- > From: Ramkumar Menon [mailto:ram.menon@xxxxxxxxxx] > Sent: Monday, June 28, 2004 2:39 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Selection of Just Attribute Nodes and Element Child Nodes > Importance: High > > Hi, > How do I select just the attribute nodes and element children from a > context node using XPath? > > for e.g. > > <foo> > <barChild at="2" anAt="3"> > <barGC> > .... > </barGC> > </barChild> > <anotherBarChild> > <abGC> > ... > </abGC> > </anotherBarChild> > </foo> > > Here what would be the query to retrieve all the child nodes and > attributes for barChild ? > /foo/barChild/?????? > In this case, I need to get just "at", anAt" and "barGC" as results. > thanks, > Ram > > > --+------------------------------------------------------------------ > 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@xxxxxxxxxxxxxxxxxxxxxx> > --+--
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Selection of Just Attribute Nodes a, Ramkumar Menon | Thread | RE: [xsl] Selection of Just Attribu, Martin.Borgars |
RE: [xsl] Selection of Just Attribu, Martin.Borgars | Date | Adding Variables, John Dwyer |
Month |