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 March 24th, 2006, 11:39 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default cant reach data in xml with namespaces

Hi!
I have a problem retriving data from xml file.

XML:
Code:
<?xml version="1.0" encoding="utf-8" ?> 
<Data xmlns="http://something.com/Documents/Schemas/doc.xsd" 
xmlns:e="http://something.com/Documents/Schemas/file.xsd">
<e:Head>
      <e:name>John</e:name> 
      <e:address1>London, UK</e:address1> 
      <e:postNumber>123456</e:postNumber>  
</e:Head>
<body>
      <age>35</age> 
      <kids>3</kids> 
      <car>ford</car>  
</body>
</Data>
XSLT:
Code:
<?xml version="1.0" encoding="windows-1250" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:edp="http://http://something.com/Documents/Schemas/file.xsd">
        <xsl:template match="/">    
                                        <xsl:value-of select="//Data/e:Head/e:name" />
                                        <xsl:value-of select="//Data/Body/age" />
        </xsl:template>
</xsl:stylesheet>
...why do i get blank output?

Thank you for your help.

 
Old March 24th, 2006, 11:52 AM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in posted xslt there is a typing error in 3rd line:
xmlns:edp="http://http://something.com/Documents/Schemas/file.xsd">

should be:
xmlns:e="http://http://something.com/Documents/Schemas/file.xsd">

...this does not solve the problem from the first post.

Thanks again for your help.

 
Old March 24th, 2006, 11:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

//Data selects nothing because there is no element in your source document called Data. There is an element called {http://something.com/Documents/Schemas/doc.xsd}Data (using James Clark's {uri}local notation for namespaced names), and to select this element you need to use the path expression

//x:Data

where some containing element (e.g. xsl:stylesheet) defines

xmlns:x="http://something.com/Documents/Schemas/doc.xsd"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 25th, 2006, 04:40 PM
TPP TPP is offline
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks alot :D

btw:
XSLT Programmer's Reference... ->great book






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ignore namespaces in input xml file hanifa XSLT 2 February 14th, 2007 04:14 AM
cant reach data in xml with namespaces TPP XSLT 1 March 24th, 2006 11:47 AM
Confused about XML namespaces planoie XSLT 2 June 2nd, 2005 04:23 AM
XML Namespaces billy_bob_the_3rd XML 1 January 31st, 2005 03:41 PM
.NET and XML Namespaces - NamespaceManager billy_bob_the_3rd XML 1 December 15th, 2004 08:51 AM





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