SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Non-Member
    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>
    And now the XSL File:

    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
    The problem seams to be this part ?Do=UserSearch&=A

    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.

  2. #2
    Sidewalking anode's Avatar
    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.

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume it is the &amp that is the cause of the problem. Here is the error I get:

    PHP Code:
    WarningSablotron error on line 10XML parser error 4not well-formed (invalid tokenin D:\Program Files\Apache Group\Apache\htdocs\rootUser3\admin\secure\classes.php on line 896
    Error
    :XML parser error 4not well-formed (invalid token

  4. #4
    Sidewalking anode's Avatar
    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;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>
    but that may be totally off.

  5. #5
    Non-Member
    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.

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your first choice done wonders.

  7. #7
    SitePoint Wizard silver trophy Karl's Avatar
    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.

  8. #8
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    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>
    &nbsp;

    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>
    and use xslt to handle the presentation...
    Last edited by Andrew-J2000; Feb 17, 2003 at 05:09.

  9. #9
    Non-Member
    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 links I could tab the links in groups of 5 and return the next line back to the original tab space though ?

    Thanks again folks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •