SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: Using PHP and XSL-T for Links
-
Feb 16, 2003, 05:30 #1
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using PHP and XSL-T for Links
Hello, I need to pass a set of dynamic links using PHP and XSL-T from XML. Can anyone help?
XML File:
PHP Code:<?xml version='1.0' ?>
<root>
<tab-title>
<bold>Manage Employee's</bold>
</tab-title>
<tab-message>You may use the Quick Search below to administer an employee.</tab-message>
<tab-spacer />
<tab-content>
[
<link href='index.php?Do=UserSearch&chr=A'>A</link> |
<link href='index.php?Do=UserSearch&chr=B'>B</link> |
...
<link href='index.php?Do=UserSearch&chr=Z'>Z</link> |
]
</tab-content>
</root>
PHP Code:<!-- ANCHORs -->
<xsl:template match = "link">
<a>
<xsl:attribute name="href">
<xsl:value-of select = "@href"/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:template>
I know this problem with entities has been solved before, though for the life of me, I cannot find it on the Net.
Any help, as always, is welcome and well recieved.
-
Feb 16, 2003, 05:33 #2
- Join Date
- Mar 2001
- Location
- Philadelphia, US
- Posts
- 2,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is the exact problem? Is the query string not passing through or are you getting a "XML not well-formed error?
By the way, it's XSLT, no hyphen.
-
Feb 16, 2003, 05:40 #3
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I assume it is the & that is the cause of the problem. Here is the error I get:
PHP Code:Warning: Sablotron error on line 10: XML parser error 4: not well-formed (invalid token) in D:\Program Files\Apache Group\Apache\htdocs\rootUser3\admin\secure\classes.php on line 896
Error:XML parser error 4: not well-formed (invalid token)
-
Feb 16, 2003, 05:53 #4
- Join Date
- Mar 2001
- Location
- Philadelphia, US
- Posts
- 2,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I took a look at the XSL list archives and you'll need to substitute & with
Code:&amp;
While the parser won't translate this into an ampersand on it's own, your browser should.
Another option may be stitching the query string together with something like(not tested, high likelihood of errors but you should get the idea:
Code:XML: <link href='index.php?Do=UserSearch'> <query> chr=Z </query> Z </link> XSL: <xsl:template match = "link"> <a> <xsl:attribute name="href"> <xsl:value-of select = "@href"/> <xsl:apply-templates /> </xsl:attribute> <xsl:value-of select="."/> </a> </xsl:template> <xsl:template match = "query"> <xsl:text>&</xsl:test> <xsl:value-of select = ".'/> </xsl:template>
-
Feb 16, 2003, 05:56 #5
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks anode
I'll have a look to see how it goes.
-
Feb 16, 2003, 05:58 #6
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your first choice done wonders.
-
Feb 16, 2003, 11:41 #7
- Join Date
- Jul 1999
- Location
- Derbyshire, UK
- Posts
- 4,411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As a general observation your XML would be better as:
Code:<?xml version='1.0' ?> <root> <tab> <title> <bold>Manage Employee's</bold> </title> <message>You may use the Quick Search below to administer an employee.</message> <content> [ <link href='index.php?Do=UserSearch&chr=A'>A</link> | <link href='index.php?Do=UserSearch&chr=B'>B</link> | <link href='index.php?Do=UserSearch&chr=Z'>Z</link> | ] </content> </tab> </root>
Karl Austin :: Profile :: KDA Web Services Ltd.
Business Web Hosting :: Managed Dedicated Hosting
Call 0800 542 9764 today and ask how we can help your business grow.
-
Feb 16, 2003, 21:33 #8
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Keep all attributes encapsulated by double quotes rather than single
PHP Code:<?xml version="1.0" ?>
<root>
<tab title="Manage Employee's" description="You may use the Quick Search below to administer an employee.">
<content>
[ <link href='index.php?Do=UserSearch&chr=A'>A</link> | <link href='index.php?Do=UserSearch&chr=B'>B</link> | <link href='index.php?Do=UserSearch&chr=Z'>Z</link> ]
</content>
</tab>
</root>
You maybe better off with something like this though
PHP Code:<?xml version="1.0" ?>
<root>
<tab title="Manage Employee's" description="You may use the Quick Search below to administer an employee.">
<link url="index.php?Do=UserSearch&chr=A" title="A" />
<link url="index.php?Do=UserSearch&chr=B" title="B" />
</tab>
</root>Last edited by Andrew-J2000; Feb 17, 2003 at 06:09.
-
Feb 17, 2003, 11:42 #9
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks folks, Andrew J2000 - your xml version looks better I think, though I'll change the links later; since I have it working just now and don't need to create more work for myself at this moment.
Karl - Good point, though there are 26 linksI could tab the links in groups of 5 and return the next line back to the original tab space though ?
Thanks again folks.
Bookmarks