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 April 26th, 2010, 11:24 AM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up XSL/XPATH namespace issue

Hello,

I am having trouble figuring out what am I doing wrong in the following transform. I think that it has something to do with the"a" namespace declaration in the input XML file.

Input XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"?>
<t:author xmlns:t="http://namespace.t.com">
		<t:basicinfo>
	<t:codename>1234</t:codename>
	<a:name xmlns:a="http://namespaces.a.com">John</a:name>
	</t:basicinfo>
</t:author>
XSL:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:t="http://namespace.t.com"
xmlns:a="http://namespaces.a.com"
>
<xsl:template match="/">
	<xsl:variable name="n" select="t:author/t:basicinfo/t:codename/text()"/>
             <!-- I don't understand why this variable does not get initialized with the next John -->
	<xsl:variable name="u" select="t:author/t:basicinfo/t:codename/a:name/text()"/>
	<Best>
	<One>
		<xsl:value-of select="$n"/>
	</One>
	<Two>
		<xsl:value-of select="$u"/>
	</Two>
	</Best>
</xsl:template>
</xsl:stylesheet>
Ouput XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Best xmlns:a="http://namespaces.a.com" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:t="http://namespace.t.com">
    <One>1234</One>
    <!--I would expect the node below to contain John as its text contents -->
    <Two></Two>
</Best>
Any input would be very much appreciated. Thank you,
Cal
 
Old April 26th, 2010, 11:28 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The name element is not a child of the codename element so I am not sure why you use that path you have.
If you use
Code:
<xsl:variable name="u" select="t:author/t:basicinfo/a:name/text()"/>
or better yet
Code:
<xsl:variable name="u" select="t:author/t:basicinfo/a:name"/>
then all should be fine.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old April 26th, 2010, 11:31 AM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thank you

Thank you Martin. I have been staring at the screen for too long





Similar Threads
Thread Thread Starter Forum Replies Last Post
default-xpath-namespace stolte XSLT 1 March 19th, 2008 12:49 PM
namespace issue 2BOrNot2B XSLT 1 March 9th, 2007 05:32 PM
XPATH: Retrieve Value without namespace prefixes ramesh.kumarm XSLT 4 September 14th, 2006 03:50 AM
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.