Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 17th, 2003, 08:17 AM
Authorized User
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath help


I have a question about how to return element nodes (not only the text) with an XPath query. For example, in the following xml:

<truck color="blue">
<truck color="green">

if I run this XPath query: "//truck[@color='blue']" all I get back is fourV-8, but I really want to get

<truck color="blue">

Does anybody know how I can do this? Or is it even possible with XPath? Maybe I just need to use DOM functions instead? Thanks in advance.

iTek Corporation
Old June 17th, 2003, 01:14 PM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

You are getting all the node, you probably need copy-of not value-of. Value-of outputs the concatenated text, copy-of outputs a deep copy:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    value-of:<xsl:value-of select="//truck[@color='blue']" /><xsl:text>#x0a;#x0d;</xsl:text>    
    copy-of:<xsl:copy-of select="//truck[@color='blue']" /><xsl:text>#x0a;#x0d;</xsl:text>



Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 March 3rd, 2008 10:58 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
XPath rupen XML 2 April 19th, 2005 09:43 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.