XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 11th, 2003, 11:12 AM
neobuddah's Avatar
neobuddah neobuddah is offline
cosmos curator
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2002
Location: Leeds, UK
Posts: 678 neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 14 h 17 m 49 sec
Reputation Power: 8
Arrow complex XPath>XML>XSLT>HTML operation - please help

Hi.

Right. I've got my content in the following format:

Code:
<system>
	<folder name="products">
		<document name="prod1">
			<author>Barry</author>
			<date>Friday 10th march</date>
			<content><![CDATA[
			lots of cdata <b>markup</b>
			]]></content>
		</document>
		<document name="prod2">
			<author>Mary</author>
			<date>Saturday 15th may</date>
			<content><![CDATA[
			lots of cdata <b>markup</b>
			]]></content>
		</document>
	</folder>
	<folder name="services">
		<document name="serv1">
			<author>Dave</author>
			<date>Friday 10th march</date>
			<content><![CDATA[
			lots of cdata <b>markup</b>
			]]></content>
		</document>
		<document name="serv2">
			<author>Bob</author>
			<date>Friday 10th march</date>
			<content><![CDATA[
			lots of cdata <b>markup</b>
			]]></content>
		</document>
	</folder>
</system>


Now, what I need to do it to export this single file as a HTML page.

Which is fine. I can get a single document node using XPath (//document[@name="serv1"]), however I need access to the folder/document relationships (including the name attribute) in XML form, so I can output a HTML list for links.



I'm basically looking to output the following:
Code:
<!-- 
* XPath(//document[@name="serv1"]) 
* Outputted elements/attributes in []
* Comments for reference.
-->

<html>
<head>
<title>[Serv1]</title>
<body>
<!-- @title, <author>, <date> -->
<div>[Serv1] - Written by [Dave] on [Friday 10th march]</div>
<!-- <content> -->
<div>[lots of cdata <b>markup</b>]</div>
<div>
<!--
* This is the bit i'm having trouble with
* I need to output this menu using XSL
* but can't get it from the XPath query,
* as far as I know.
-->
<ul>Menu
  <li>[Products]</li>
    <ul>
    <li>[Prod1]</li>
    <li>[Prod2]</li>
    </ul>
  <li>[Services]</li>
    <ul>
    <li>[Serv1]</li>
    <li>[Serv1]</li>
    </ul>
</ul>
</div>
</body>
</html>


I'm tearing my hair out - I'm not very "up" on XSL/XPath and this needs to be done simple and quickly using PHP, flat XML files, and flat XSL files.

Thanx in advance.
__________________
R.T.F.M - Its the only way to fly...

"No matter what you do, or how good it is, someone will always ask for more features. Or to change the colour of something, then change their minds."

Personal:
experience// 8 Years Web Development
technologies// Standards-compliant, valid, & accessible (x)HTML/CSS, XML/XSL/XPath/XQuery/XUpdate, (OOP) PHP/(My)SQL, eXist/Xindice/XMLDBs
packages// Photoshop, Illustrator, Flash/Fireworks/Director
environment// FC2, MySQL, Lighttpd, PHP5, Mojavi/Agavi
site// //refactored.net/ (Coming soon...)
quote// Programming is the eternal competition between programmers who try to make apps more and more idiot proof and the universe that makes dumber idiots. So far, the universe is winning...

Reply With Quote
  #2  
Old September 12th, 2003, 02:22 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Well, this will give you the html you're after:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/system">
	<ul>Menu
		<xsl:apply-templates />
	</ul>
</xsl:template>

<xsl:template match="/system/folder">
	<li>[<xsl:value-of select="@name"/>]</li>
	<ul>
		<xsl:apply-templates />
	</ul>
</xsl:template>

<xsl:template match="/system/folder/document">
	<li>[<xsl:value-of select="@name"/>]</li>
</xsl:template>

<xsl:template match="text()">
	<!-- skip all text -->
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #3  
Old September 12th, 2003, 02:59 AM
neobuddah's Avatar
neobuddah neobuddah is offline
cosmos curator
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2002
Location: Leeds, UK
Posts: 678 neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 14 h 17 m 49 sec
Reputation Power: 8
Don't I have to do an external query using PHP to get two seperate result sets - one of all the menu nodes, and another for the document nodes?

Reply With Quote
  #4  
Old September 12th, 2003, 12:58 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Well, I'm not entirely sure what you mean about querying. Based on your other posts I'm thinking that you mean querying the xml file with an xpath expression to extract a specific piece. For the menu you don't want to do that. You want to do an xsl transformation on the *entire* xml file.

Reply With Quote
  #5  
Old September 15th, 2003, 05:10 AM
neobuddah's Avatar
neobuddah neobuddah is offline
cosmos curator
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2002
Location: Leeds, UK
Posts: 678 neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level)neobuddah User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 14 h 17 m 49 sec
Reputation Power: 8
Ah... I thought I had to have two XML files.

I'm accessing an XMLDB, so I'd be able to query twice.

No matter though, I think it would be more efficient calling the original XML file and using XSL for that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > complex XPath>XML>XSLT>HTML operation - please help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT