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 June 29th, 2011, 09:10 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default Tag With Multiple namespaces in Xpath

Hi,

I'm writing an xsl transform to change data quite significantly (different schemas).

I'm having an issue with namespaces, which I have read up on but am still struggling with a certain problem. I have searched the forum for it but to no avail.

The start xml contains this code (namespaces simplified for ease...):
Code:
<s:Envelope xmlns:s="ssssss">
<s:Body>
<GetQuoteResponse xmlns="hhhhhh">
  <GetQuoteResult xmlns:a="aaaaa" xmlns:i="iiiii">
    <a:Charges>
        <a:Amount>123</a:Amount>
        <a:Name>XYZ</a:Name>
    </a:Charges>
A namespace "h" is defined in the top of the stylesheet with the value hhhhhh.

In the xsl, I have xpath to return the amount, which looks like:
Code:
<xsl:value-of select="s:Envelope/s:Body/h:GetQuoteResponse/GetQuoteResult/a:Charges/a:Amount" />



This doesn't work and I can see that it is because of the GetQuoteResult - I have tried it with namespaces a and i (e.g. a:GetQuoteResult) but these don't work either.

My question is what namespace I should be using to get the xpath to work?
The two defined namespaces are throwing me, if there was one (like the GetQuoteResponse tag) then it would make more sense.

It seems that having a namespace defined in the top of the stylesheet, and some defined within the xml being ouput, is messy so if someone could advise how to tidy these up as well that would be great.

Thanks,
Neil
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
 
Old June 29th, 2011, 09:14 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

GetQuoteResults has not prefix, so it is in the namespace defined with no prefix. Looking at the GetQuoteResults element it defined two namespaces, both of which have prefixes, so its not them.

Going up a level you see the parent element defines the 'hhhhh' namespace with no prefix, therefore the GetQuoteResults is in that namespace.

If in your XSLT you have defined the 'h' prefix for the 'hhhhh' namespace then h:GetQuoteResults is what you need.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
Belch (July 4th, 2011)
 
Old July 4th, 2011, 08:14 AM
Authorized User
 
Join Date: Nov 2007
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thanks Sam, that's made it a lot clearer - I added the previous tag namespace (h:) as you suggested and this works fine now.

Thanks again,
__________________
Neil Belch
Technical Officer
CDL

The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
NameSpaces and Multiple Main rodbiser BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 0 September 11th, 2009 05:48 PM
How to get value from xpath in value-of tag dishant XSLT 8 May 12th, 2009 06:22 AM
How to use XPath to retrieve a node tag rs:data? y10k XML 1 May 5th, 2006 01:11 PM
how to write multiple namespaces in soap envelope monuindia2002 XML 0 March 1st, 2006 02:29 AM
Accessing XML Node with multiple namespaces bamirzada C# 0 August 14th, 2003 07:41 PM





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