Subject: Re: Do you know how to refer to a node? From: Steve Tinney <stinney@xxxxxxxxxxxxx> Date: Sun, 19 Dec 1999 19:50:22 -0500 |
Jonathan Asbell wrote: > > I need to refer to > node(0) > node(1) > node(2) > etc. which are children of a node "CUSTOMER". How do I refer to each > successive node child of node "CUSTOMER"? My aim is to transform this into > xml with more meaningful tag names > > <CUSTOMER> > <xsl:text>WHITC</xsl:text> > <xsl:text>White Clover Markets</xsl:text> > <xsl:text>Karl Jablonski</xsl:text> > <xsl:text>Owner</xsl:text> > <xsl:text>305 - 14th Ave. S.<BR>Suite 3B</xsl:text> > <xsl:text>Seattle</xsl:text> > <xsl:text>WA</xsl:text> > <xsl:text>98128</xsl:text> > <xsl:text>USA</xsl:text> > <xsl:text>(206) 555-4112</xsl:text> > <xsl:text>(206) 555-4115</xsl:text> > </CUSTOMER> > Is your input really marked up with <xsl:text>? Assuming input like this: <nodes> <a>1</a> lalala <b>2</b> </nodes> You can either let your templates do the walking: <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="nodes"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="nodes"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="*|text()"> <node> <xsl:value-of select="normalize-space(.)"/> </node> </xsl:template> </xsl:stylesheet> Or iterate over the node list explicitly: <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="nodes"/> <xsl:template match="/"> <nodes> <xsl:for-each select="/nodes/node()"> <node><xsl:value-of select="normalize-space(.)"/></node> </xsl:for-each> </nodes> </xsl:template> </xsl:stylesheet> Steve XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Do you know how to refer to a n, John Robert Gardner | Thread | Re: Do you know how to refer to a n, Steve Tinney |
Re: Templates aplied to namespaces, Mark D. Anderson | Date | Re: Do you know how to refer to a n, Steve Tinney |
Month |