Web Design and Development Forums

Need help on xsl and xpath

This is a discussion on "Need help on xsl and xpath" within the XML, RSS & Atom section. This forum, and the thread "Need help on xsl and xpath are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > XML, RSS & Atom

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Dec 12th, 2006, 22:12   #1 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Need help on xsl and xpath

Hi all,
I'm having problem with my xsl project.I want to display all the xml data in a table using xsl.
My problem is why all my table display the same data(only the first data displayed and being repeated in other table).it seems that the program does not iterate even if i'm using for each.Can somebody help me????
XML file contains:

<tpeg_document generation_time="2006-11-28T02:44:56+0" >
<tpeg_message >
<originator country="UK" originator_name="BBC Travel News" />
<summary lang="en" > A8014 West Dunbartonshire - Traffic light failure on Kilbowie Road both ways at the A82 Great Western Road junction.
</summary>
.....
.....
.....

</tpeg_message>
<tpeg_message>.........</tpeg_message>

My XSL file:

<xsl:template match="tpeg_document" >
<xsl:apply-templates />
</xsl:template>
<xsl:template match="tpeg_message" >
<table border="1">
<xsl:for-each select="." >
<th colspan="2">Traffic Incidents</th>
<tr>
<td><b>Time of Incidents</b></td>
<td><xsl:value-of select="//@message_generation_time" /></td>
</tr>
<tr>
<td><b>Severity Factor</b></td>
<td><xsl:value-of select="//@severity_factor" /></td>
</tr>
<tr>
<td><b>Latitude</b></td>
<td><xsl:value-of select="//@latitude" /></td>
</tr>
<tr>
<td><b>Longitude</b></td>
<td><xsl:value-of select="//@longitude" /></td>
</tr>
<tr>
<td><b>Summary</b></td>
<td><xsl:value-of select="//summary" /></td></tr>
</xsl:for-each>
</table>
</xsl:template>
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 08:51   #2 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

The problem is the '//'s you are using before every selection. They select the first matching thing in the document that they come accross, which is why you're getting the first values repeated.

You need to define your xpath specifically for where you are in the document. Most of them shouldn't need the '//'s at all.


Post more on the problem if you're having trouble getting the XPath values.

Snow

P.S. I'm not really seeing the point in the 'originator' node, it seems to be just attributes - unless you allow values in some circumstances? If not I'd add it's attributes to the 'tpeg_message' attributes as it would be a lot cleaner. Just an idea...
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 10:21   #3 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

Snow,thanks for your suggestion.I try to remove the "//" but it did not work out.The data is not diplayed at all.I'm new to XSL.This is my first project using XSL.Thanks..Hope you can help !!!
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 10:27   #4 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

Could you post up your DTD?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:00   #5 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

i am given only the xml file.i need to create xsl to display the xml data.is it possible to work out without the dtd file?
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:07   #6 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

Oh, before you think XPath stuff, then the XSLT needs sorted as you're using apply-template & a for-each; which I'm pretty sure will not work together in this context - you're drilling in a level too deep.

I'd advice you to take out the 'for-each' and stick with the apply-template.

Snow
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:24   #7 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

thanks snow..i have remove the for each and i put <td><xsl:value-of select="./summary" /></td>..it show me all the different data in each table.the problem now is all the attributes do not display.I put it in the same format..<td><xsl:value-of select="./@latitude" /></td> but it didnt work..thanks
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:30   #8 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

could I see how your DTD and XSLT look now please?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:33   #9 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

XML file contains:

<tpeg_document generation_time="2006-11-28T02:44:56+0" >
<tpeg_message >
<originator country="UK" originator_name="BBC Travel News" />
<summary lang="en" > A8014 West Dunbartonshire - Traffic light failure on Kilbowie Road both ways at the A82 Great Western Road junction.
</summary>
.....
.....
.....

</tpeg_message>
<tpeg_message>.........</tpeg_message>

My XSL file:

<xsl:template match="tpeg_document" >
<xsl:apply-templates />
</xsl:template>
<xsl:template match="tpeg_message" >
<table border="1">

<th colspan="2">Traffic Incidents</th>
<tr>
<td><b>Time of Incidents</b></td>
<td><xsl:value-of select="./@message_generation_time" /></td>
</tr>
<tr>
<td><b>Severity Factor</b></td>
<td><xsl:value-of select="./@severity_factor" /></td>
</tr>
<tr>
<td><b>Latitude</b></td>
<td><xsl:value-of select="./@latitude" /></td>
</tr>
<tr>
<td><b>Longitude</b></td>
<td><xsl:value-of select="./@longitude" /></td>
</tr>
<tr>
<td><b>Summary</b></td>
<td><xsl:value-of select="./summary" /></td></tr>
</table>
</xsl:template>
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:38   #10 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

Oh, sorry, didn't see your post above...

Where in your XML do you enter values for those attributes you're trying to recover? Have you skipped some of the XML document on here?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:42   #11 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

<tpeg_document generation_time="2006-11-28T02:44:56+0" >
<tpeg_message >
<originator country="UK" originator_name="BBC Travel News" />
<summary lang="en" > A8014 West Dunbartonshire - Traffic light failure on Kilbowie Road both ways at the A82 Great Western Road junction.
</summary>
<road_traffic_message message_id="1333854" message_generation_time="2006-11-28T02:34:30+0" version_number="2" start_time="2006-11-28T02:04:28+0" stop_time="2006-11-28T03:34:30+0" severity_factor="severe" >
<facilities_performance >
<traffic_control traffic_control_type="traffic lights" traffic_control_status="not working" >
<position position="all driving lanes" />
</traffic_control>
</facilities_performance>
<location_container language="English" >
<location_coordinates location_type="route" >
<WGS84 latitude="55.91857" longitude="-4.405708" />
<location_descriptor descriptor_type="road number" descriptor="A8014;Kilbowie Road" />
<location_descriptor descriptor_type="town name" descriptor="West Dunbartonshire" />
<location_descriptor descriptor_type="Junction with" descriptor="A82;Great Western Road" />
<location_descriptor descriptor_type="and " descriptor="B814;Duntocher Road" />
<direction direction_type="both ways" />
</location_coordinates>
</location_container>
</road_traffic_message>
</tpeg_message>
<tpeg_message >

I only post one section of tpeg_message
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:45   #12 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

does plain:
<td><xsl:value-of select="@latitude" /></td>

not work?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:52   #13 (permalink)
New Member
 
Join Date: Dec 2006
Location: UK
Age: 27
Posts: 7
Re: Need help on xsl and xpath

ok snow...now it works...thanks for your help..thanks a lot
emeakashah is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Dec 13th, 2006, 11:53   #14 (permalink)
Reputable Member
 
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 370
Send a message via MSN to snow
Re: Need help on xsl and xpath

No problem! Glad it's sorted
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
xpath, xsl

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
xpath node names Don Logan XML, RSS & Atom 0 Mar 23rd, 2006 14:19



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 15:16.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59