Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT 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 September 14th, 2006, 01:17 AM
Authorized User
 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default XPATH: Retrieve Value without namespace prefixes

Hello everyone,
Kindly help me in solving this issue.
This is the XML file
<test:New_Service_Request xmlns:test="http://test.com">
<test:Message_Type>abcdef</test:Message_Type>
<test:Message_Source>FlowStream</test:Message_Source>
<test:Message_Id>800043660</test:Message_Id>
</test:New_Service_Request>

Need XPATH to retrieve the value 'abcdef' without giving the namespace. I mean normally we give //*/test:MessageType in value-of to retieve it. But now these messages change dynamically.
So the namespace changes too. Hence one can't rely on the namespace to retrieve this info.

My Question: Is there by any means by omitting this namespace we could do a xpath to retrieve 'abcdef'?
PLZ PLZ help......in a very urgent sutation.

THANX A LOT!

ramesh.
__________________
Ramesh
\"Always Look For Something NEW\"
 
Old September 14th, 2006, 02:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Saying that you want to retrieve an element called Message_Source without knowing what namespace it's in is a bit like saying you want to go to London but you're not sure whether it's London, Ontario or London, England. It suggests there's something very fishy in the way you are using namespaces.

However, you can do it. In XPath 2.0 you can do select="*:Message_Source", in 1.0 you can do select=*[local-name()='Message_Source]". It may not be especially efficient.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 14th, 2006, 03:21 AM
Authorized User
 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default

Thanx for your prompt reply Michael.
But i need to extract the value of the Message_Source and the not Message_Source string. If i wanted to extract the word Message_Source, then i might have used local-name(*/*[2])
Unfortunately i need the value it holds. 'abcdef' is what i need.
Do you have any suggestions on this.
thanx a lot.

ramesh

 
Old September 14th, 2006, 03:37 AM
Authorized User
 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default

Hey Michael, you know what - i got through with this.

//*/*[local-name()='Message_Source']

Anyway, thanx a lot for your help Mike.

ramesh

 
Old September 14th, 2006, 03:50 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Using select=*[local-name()='Message_Source']" as I suggested will select the Message_Source node (assuming you are currently at its parent). You can then extract the string value of the node in the normal way.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not using Namespace prefixes stuohy XSLT 6 June 19th, 2012 04:23 PM
default-xpath-namespace stolte XSLT 1 March 19th, 2008 12:49 PM
How to use XPath to retrieve a node tag rs:data? y10k XML 1 May 5th, 2006 01:11 PM
Access Namespace Node using XPath pvasudevan XSLT 1 January 2nd, 2006 06:20 AM
XPath matching with a default namespace rich_unger XSLT 5 December 4th, 2003 01:22 AM





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