[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Do you know how to refer to a node?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|