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 30th, 2012, 02:15 PM
Registered User
 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default getting Namespace uri

Hi,
I am using xsl 1.0. I need to get the namespace uri from prefix.

here is my xml,

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:a1="http://abc.com/arthemetic/integers/a1">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<a1:add>
</a1:add>
</soapenv:Body>
</soapenv:Envelope>


i want to get the namespace uri for prefix a11 is http://abc.com/arthemetic/integers/v1


Here is the code that i am trying out,


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>

<xsl:template match="/">
<xsl:variable name="operationName">
<xsl:value-of
select="name(/*[local-name()='Envelope']/*[local-name()='Body']/*[1])"></xsl:value-of>
</xsl:variable>
<xsl:variable name="prefix">
<xsl:value-of select="substring-before($operationName, ':')"></xsl:value-of>
</xsl:variable>
<xsl:variable name="ns-node"
select="namespace::node()[.= $prefix]" />
dfadsfdfadsf
<xsl:value-of select="$ns-node" />
</xsl:template>
</xsl:stylesheet>

But i am not receiving the namespace. Am i missing anything over here.
 
Old June 30th, 2012, 02:56 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

namespace-uri() is the function which returns the namespace for a particular node. Not sure what you are trying to do with it but there you go.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 30th, 2012, 06:32 PM
Registered User
 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In one of my requirement, i need to get the namespace uri of the operation in the soap request.

the idea is we need to get the first element namespace uri that comes immediately after soap:body. In the below example add method comes after soap:body, so i need to know the name space uri for that prefix.
 
Old June 30th, 2012, 07:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First, please avoid the habit of writing

Code:
<xsl:variable name="operationName">
<xsl:value-of select="X"/>
</xsl:variable>
when you could write

Code:
<xsl:variable name="operationName" select="X"/>
which is shorter, more readable, and far more efficient (because it avoids the need to construct a tree). I don't know why the former form is encountered so often - it's a very common but really bad mistake.

Secondly, instead of

Code:
namespace::node()[.= $prefix]
you want

Code:
namespace::node()[name() = $prefix]
A namespace node represents a prefix, uri pair, with the prefix being the name of the node and the uri being its string value.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 30th, 2012, 08:35 PM
Registered User
 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your comments Kay.
I have tried with your comments, but still i am seeing the result.

Here is my request xml

Code:
   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:v11="http://abc.com/arthemetic/integers/v1">
	<soapenv:Header>
	</soapenv:Header>
	<soapenv:Body>
		<v11:add>
		</v11:add>
	</soapenv:Body>
</soapenv:Envelope>
Code:

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">


	<xsl:template match="/">

		<xsl:variable name="operationName"
			select="name(/*[local-name()='Envelope']/*[local-name()='Body']/*[1])" />


		<xsl:variable name="prefix"
			select="substring-before($operationName, ':')" />

		sdfdadssdf
		<xsl:value-of select="namespace::node()[name() = $prefix]" />
	</xsl:template>
</xsl:stylesheet>
 
Old June 30th, 2012, 09:07 PM
Registered User
 
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

there is typo, I am not able to get the namespace uri for v11 prefix
 
Old July 1st, 2012, 04:57 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The following gives you the namespace for the first child of the Body element. It is much simpler than what you appear to be trying above.

<xsl:value-of select="namespace-uri(/soapenv:Envelope/soapenv:Body/*[1])"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
tagdir uri thelemur BOOK: Beginning JavaServer Pages 0 May 26th, 2011 09:48 AM
error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'Syste shailesh_kumar C# 2008 aka C# 3.0 8 August 20th, 2009 03:11 AM
Need to convert an existing namespace and add new namespace to the SOAP xml Prabeen XSLT 10 April 28th, 2009 10:18 AM
Referrer and Uri druid2112 General .NET 1 April 20th, 2004 12:54 PM





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