[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: select only some elements and attributes
Hi Meili, > Hi, What's the best way to only select some elements and attributes > using xslt? Evan's shown you one way (a push method), which involves selecting all the elements and attributes, copying most of them and not copying the ones that you don't want. That's the easiest way to do it if you want to copy the majority of the nodes, and just want to leave out a few (or if the nodes that you want to leave out are easily identified). If you want to only keep a smaller proportion of the nodes, then it's best to select the ones that you *do* want to keep and just copy those (a pull method). In your case, this alternative gives something like: <xsl:template match="product"> <xsl:copy> <xsl:copy-of select="@sku" /> <xsl:copy-of select="title" /> <xsl:copy-of select="price" /> <xsl:copy-of select="weight" /> <xsl:apply-templates select="vendor" /> </xsl:copy> </xsl:template> <xsl:template match="vendor"> <xsl:copy> <xsl:copy-of select="company" /> <xsl:copy-of select="phone" /> </xsl:copy> </xsl:template> If the ordering in the source and the result is the same, then you can combine the xsl:copy-of instructions together to make it shorter: <xsl:template match="product"> <xsl:copy> <xsl:copy-of select="@sku | title | price | weight" /> <xsl:apply-templates select="vendor" /> </xsl:copy> </xsl:template> <xsl:template match="vendor"> <xsl:copy> <xsl:copy-of select="company | phone" /> </xsl:copy> </xsl:template> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ 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
|