|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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... |
|
#2
|
|||
|
|||
|
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> |
|
#3
|
||||
|
||||
|
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?
|
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > complex XPath>XML>XSLT>HTML operation - please help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|