473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with XSL unable to select elements from xml file

108 100+
Greetings,
I'm using XMLspy and haveing problem selecting any child nodes under complex element type <DeliveryInfo>

Can anyone point out where im going wrong?
Im a complete newbie to XML, XSD and XSL.

Thanks
Rob

extract from XML file
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- edited with XMLSpy v2007 (http://www.altova.com) by Rob W -->
  3. <PODBatch xmlns="http://my-pod/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my-pod/namespace E:\DOCUME~1\Rob\Desktop\POD02.XSD">
  4.     <POD>
  5.         <DeliveryInfo>
  6.             <DeliveryNoteNo>DN012345</DeliveryNoteNo>
  7.             <DeliveryDateTime>01/11/07 10:35</DeliveryDateTime>
  8.             <DeliveryDrivername>Bill Egg</DeliveryDrivername>
  9.             <DeliveryDriverSignature>B.Egg</DeliveryDriverSignature>
  10.             <DeliveryStatus>In transit</DeliveryStatus>
  11.         </DeliveryInfo>
Full XSL file

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xsi ="http://www.w3.org/2000/10/XMLSchema-instance"
  4. xmlns:my="http://my-pod.com/namespace">
  5.  
  6. <xsl:template match="/">
  7.     <html>
  8.         <Header>    
  9.             <img src="http://i140.photobucket.com/albums/r13/robtyketto/truck-clipart-icon2_ys61.gif" align="left"/>
  10.         <h2>Proof-of-Delivery</h2>
  11.         <xsl:apply-templates select="//my:POD/DeliveryInfo"/>
  12.         <br></br>
  13.         <hr></hr>        
  14.         </Header>
  15.         <body>
  16.          <h3>Sender:</h3>
  17.         <address>
  18.         Company<br />    
  19.         Address Place<br />
  20.         Nothing Road<br />
  21.         Walton-on-Thames<br />
  22.         Surrey<br /> 
  23.         KT29 4ZZ<br />
  24.      </address>
  25.         </body>    
  26.     </html>
  27. </xsl:template>
  28.  
  29. <xsl:template match="my:POD/DeliveryInfo">
  30.             <strong>Deliver Note No: </strong>xsl:value-of select="my:DeliveryNoteNo"><br/><br></br>   
  31. </xsl:template>
  32.  
  33. </xsl:stylesheet>
Nov 5 '07 #1
7 1675
jkmyoung
2,057 Expert 2GB
The namespace prefix needs to be applied to all elements in the xpath:

<xsl:apply-templates select="//my:POD/my:DeliveryInfo"/>

<xsl:template match="//my:POD/my:DeliveryInfo"/>
Nov 5 '07 #2
robtyketto
108 100+
Thanks for the advice for this post and all the others Ive rencently posted.

The XSL is well formed but its not matching with anything still as the words
"Deliver Note No:" are not being printed or the element value being selecting.

It does produce the other output just it appears not to be able to match the elements.

Is it something to do with the structure of the XML file?

<PODBATCH> Root Element
<POD>
<DeliveryInfo>
<DeliveryNoteNo>

Changed code below:-

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.     <html>
  3.         <Header>    
  4.             <img src="http://i140.photobucket.com/albums/r13/robtyketto/truck-clipart-icon2_ys61.gif" align="left"/>
  5.         <h2>Proof-of-Delivery</h2>
  6.         <xsl:apply-templates select="//my:POD/my:DeliveryInfo"/>
  7.         <br></br>
  8.         <hr></hr>        
  9.         </Header>
  10.         <body>
  11.          <h3>Sender:</h3>
  12.         <address>
  13.         Walton-on-Thames<br />
  14.         Surrey<br /> 
  15.         KT19 4ZZ<br />
  16.      </address>
  17.         </body>    
  18.     </html>
  19. </xsl:template>
  20.  
  21. <xsl:template match="my:POD/my:DeliveryInfo">
  22.             <strong>Deliver Note No: </strong>xsl:value-of select="my:DeliveryNoteNo"><br/><br></br>   
  23. </xsl:template>
  24.  
  25. </xsl:stylesheet>
Nov 5 '07 #3
jkmyoung
2,057 Expert 2GB
The namespaces subtly don't match
xml: http://my-pod/namespace
xsl: http://my-pod.com/namespace

Fix this error, and you should have it.
Nov 5 '07 #4
robtyketto
108 100+
Thanks problem solved.

Reading up on xpath now to get my head around selection of child/parent elements to complete my work.

Cheers
Rob
Nov 5 '07 #5
robtyketto
108 100+
OK so now I am confused.

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="my:POD/my:DeliveryInfo">
  2.             <strong>Delivery Note No: </strong><xsl:value-of select="my:DeliveryNoteNo"/>
  3. </xsl:template>
Xpath finds the match as its printing "Delivery Note No "but not the value of the element.

As Im already in the correct path I thought all I need to do was reference the element.

Very confused.

When I had'nt quite got the syntax right I accidentally selected all the values of DeliveryInfo and now I cant select a single element.

Expand|Select|Wrap|Line Numbers
  1. <POD>
  2.         <DeliveryInfo>
  3.             <DeliveryNoteNo>DN012345</DeliveryNoteNo>
  4.             <DeliveryDateTime>01/11/07 10:35</DeliveryDateTime>
  5.             <DeliveryDrivername>Bill Egg</DeliveryDrivername>
  6.             <DeliveryDriverSignature>B.Egg</DeliveryDriverSignature>
  7.             <DeliveryStatus>In transit</DeliveryStatus>
  8.         </DeliveryInfo> 
Nov 5 '07 #6
jkmyoung
2,057 Expert 2GB
I can't tell at the moment, could your repost your xslt and xml?
Nov 6 '07 #7
robtyketto
108 100+
I resolved the problem, I cant believe it myself but sometimes I was seeing values and others I wasnt without any XML changes.

I resolved all issues by installing a copy of xmlspy from my university.
Im putting down all my headaches to a bugged copy.

Thanks for all the replies
Rob
Nov 7 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: will | last post by:
Trying to modify some code from : http://www.faqts.com/knowledge_base/view.phtml/aid/2357 But having some problems. Cant work out how/why its not adding rows in the right place. seems strange to...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
9
by: please-answer-here | last post by:
What is wrong with this code? when i place "return false" before the xfab assignment the form as intended doesn't submit. But when placed as here or in the last if/else construct the page gets...
55
by: drhowarddrfine | last post by:
I'm working on a web site that could use some control using js but am concerned about what problems I may have with potential users having their js turned off. Has anyone had any serious problems...
6
by: Mike | last post by:
http://www.calgarymike.com/content/fsbo.html After having validated a couple of pages I'm completely stumped as to why I get this message. I don't have a line counter in my program (Arachnophia)...
6
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these...
3
by: Anders Borum | last post by:
Hello! I've come across a strange error that occurs, when you try to return a nodelist from a variable with a choose/where/otherwise statement. I'm not quite sure whether it's a bug or simply...
3
by: kathyk | last post by:
Hi All, I am using Access 2003 on machines with windows 2000 and XP. The problem I'm having started only after we got a new image for our PC's. This database app has been around for awhile and...
7
meenakshia
by: meenakshia | last post by:
hi forum i have been trying to use a way to validate my form but i was unable to use it properly pls rectify my mistakes. i m using input type as a button and calling a function to save the form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.