CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignCSS Help

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 July 5th, 2002, 02:18 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
XSLT transform prob along with PHP & CSS

greetings all,

i have a simple xml doc which serves as the content of a links page on a web site..

it goes something like this:

<?xml version="1.0"?>
<links.page>
<link>
<title>Devshed</title>
<url>http://www.devshed.com</url>
</link>
<link>
<title>Some Site</title>
<url>http://www.some.com</url> </link>
</links.page>

i have successfully made an xslt to html transformation, however when i attempt to include the xml file in a web page generated with php.. i receive a parsing error.... line 1?????

in addition, my css style sheet doesn't affect the links generated with xslt. is this suppose to happen?? how can i remedy this?

also, when viewing the xml doc with netscape 6.2, the only result is the text contained within the xml doc????
there are quite a few issues here i'm sure, so any help sorting it all out is greatly apprectiated..
thank you!


_justin.dago

PS:
here is my xsl stylesheet:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<table bgcolor="#999999">
<xsl:apply-templates/>
</table>
</xsl:template>

<xsl:template match="/links.page">
<xsl:for-each select="link">
<tr><td>
<a class="sub_nav_links"><xsl:attribute name="href">"<xsl:value-of select="url"/>"</xsl:attribute><xsl:value-of select="name"/></a></td></tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #2  
Old July 16th, 2002, 02:26 PM
petrik petrik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 petrik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You can put a href in an XSL like this:

Code:
<xsl:element name="a">
  <xsl:attribute name="href">
    <xsl:value-of select="url" />
  </xsl:attribute>
  <xsl:value-of select="title" />
</xsl:element>





You can even make more compicated href's
like: index.php?action=insert_product

Code:
<xsl:element name="a">
  <xsl:attribute name="href">
    <xsl:value-of select="PHP_SELF"/>?<![CDATA [action=insert_product]]></xsl:attribute>
	insert new product
    </xsl:element>


Your XML file should look like this for the above example:

Code:
<?xml version=\"1.0\"?>
	    <main>
	      <PHP_SELF>$PHP_SELF</PHP_SELF>
	    </main>

Reply With Quote
  #3  
Old July 16th, 2002, 11:44 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
petrik,

first let me thank you for the response, and your passing of knowledge to me.

i have several more questions:

is my xml file incorrect??
is your xsl doc an alternative? or the proper way to accomplish my task?
how bout the parse error when i include() the xml file?? can this not be done?


now in xsl stylesheet will generate "default" styled links? (that is style defined in a:link) how about css classes?

justin.dago

Reply With Quote
  #4  
Old July 17th, 2002, 02:24 AM
petrik petrik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 petrik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Your xml file is correct. I opened it in explorer 5 and it didn't give any errors. Also in your xml file you used 'title' in your xsl file you used 'name'.


For your classes just add another attribute:

Code:
<xsl:element name="a">
  <xsl:attribute name="class">sub_nav_links</xsl:attribute>
  <xsl:attribute name="href">
    <xsl:value-of select="url" />
  </xsl:attribute>
  <xsl:value-of select="title" />
</xsl:element>


It's one way to accomplish this and the most flexible.

Another less flexible (when using URL's like ?action=a&id=b) is:

Code:
<a class="sub_nav_links" href="{url}">title</a>


The following worked for me.:

xml file:
Code:
<?xml version="1.0"?> 
<links.page> 
<link> 
<title>Devshed</title> 
<url>http://www.devshed.com</url> 
</link> 
<link> 
<title>Some Site</title> 
<url>http://www.some.com</url> </link> 
</links.page>


xsl file:
Code:
<?xml version="1.0"?> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
<table bgcolor="#999999"> 
<xsl:apply-templates/> 
</table> 
</xsl:template> 

<xsl:template match="/links.page"> 
<xsl:for-each select="link"> 
<tr><td> 
<xsl:element name="a">
  <xsl:attribute name="class">sub_nav_links</xsl:attribute>
  <xsl:attribute name="href">
    <xsl:value-of select="url" />
  </xsl:attribute>
  <xsl:value-of select="title" />
</xsl:element>
</td></tr> 
</xsl:for-each> 
</xsl:template> 
</xsl:stylesheet>



php file (with sablotron enabled):
Code:
<?php

// store XML and XSL content as variables
$xmlstring = join('', file(test.xml'));
$xslstring = join('', file('test.xsl'));

// call the XSLT processor directly
xslt_process($xslstring, $xmlstring, $result);

// output the result
echo $result;
?>

Last edited by petrik : July 18th, 2002 at 01:53 AM.

Reply With Quote
  #5  
Old July 17th, 2002, 05:35 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
ahhh... didn't see the name/ title thing, that might not be in my original, i have to go back and check. it may also be why the links weren't exactly correct...

once again thank you...
so i just had to take it one step further and set another attribute.. got it

the sablotron code is to link the xml files to the php script???

and as for sablotron, this poses another question, which has been on my mind..

do you recommend any particular method for processing xml docs...

sax, dom, xsl, don't know really anything about sablotron, (i'll have to do some reading, think there's a few articles on devshed) but...
(i may be mixing some technologies...)
do these all accomplish relatively the same tasks???

right now, i'm pretty new to xml and its friends. this links doc is academic..it's meant for a personal site..to sort of demonstrate that i am capable of working with xml to perspective employers...
can you or anyone recommend some other ways of incorporating xml into my site???

youngpup.net makes some cool use of xml, i believe he generates his tree style navigation with xml???
do you or anyone know of any resources(tutorial, etc.) that show how to create this navigation system??

there are quite a few questions here, and i apologize for the length of the response, but how will i ever learn anything?

any help is greatly appreciated!!

justin.dago

Reply With Quote
  #6  
Old July 18th, 2002, 02:06 AM
petrik petrik is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 petrik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sablotron is a xml/xslt parser. It's optimized for parsing a xml file through a xslt file.
If this is what you you will be doing, I'd recommend Sablotron. (Just make sure your Host supports Sablotron.)

The 3 pieces of code are all you need for parsing the xml.

The Sax and Dom parsers are for reading different xml file's where you don't know the exact structure and/or tags.

Sax: reads line for line.
Dom: reads the whole document and knows what are all the parents and children. And it is there for much more CPU intensive.

Reply With Quote
  #7  
Old July 18th, 2002, 02:56 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
petrik,

did you happen to check that site:
youngpup.net??

any thoughts on other uses for xml in my site??

read the sablotron article, so i'm straight on that, pretty nice, and pretty simple.

justin.dago

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > XSLT transform prob along with PHP & CSS

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap