1

Can someone point me to a tutorial on this? i've looked at some similar questions on Stackoverflow and looked at PHP DOM in the manual.

I have an XML document and at two particular tags want to output data from my database, otherwise still output the other tags and the info within them.

So I want to grab the info in a query to automatically insert the home and away line-ups dynamically.

<root>
    <sometag>Some text here</sometag>
    <anothertag>Something else here</anothertag>

    <Hometeam>Cardinals</Hometeam>
        <HomeLineup></HomeLineup> -- this would be database driven data

    <Awayteam>Giants</Awayteam>
        <AwayLineup></AwayLineup> -- this would be database driven data

    <yetmoretags>Other stuff</yetmoretags>

</root>

I see an example here that would create an xml file: Using PHP DOM to create XML files from MySQL data

but a) I'm not sure how I would ensure the other xml tags and content would get spit out and b) not sure how I would load those file/files or at what point they would be outputted.

Really I'm making a full page with some other content, php and javascript related and am not sure the best method to output the database content within the specific DOM tags.

I've looked at the PHP DOM docs and understand how to manipulate and find a specific tag but don't know how to output the entire document but specifically within that document include dynamic content.

Community
  • 1
  • 1
Niagaradad
  • 453
  • 3
  • 10

1 Answers1

0

A template like this:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xhtml xsl xs"> 

<xsl:output method="html" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" indent="no"/> 

  <!-- match and copy verbatim everything - unless there is another template for it -->
  <xsl:template match="@*|node()"> 
        <xsl:copy> 
            <xsl:apply-templates select="@*|node()"/> 
        </xsl:copy> 
  </xsl:template> 

  <xsl:template match="HomeLineup"> 
        <xsl:copy> 
            <!-- do something here --> 
        </xsl:copy> 
  </xsl:template> 

  <xsl:template match="AwayLineup"> 
        <xsl:copy> 
            <!-- do something here --> 
        </xsl:copy> 
  </xsl:template> 

</xsl:stylesheet>
Mike
  • 35
  • 4
  • Note: [1] The template that matches everything - makes sure all of your content gets copied over. [2] the other templates will match your specific tags. [3] change the stylesheet and output declarations to match your needs – Mike Jan 25 '13 at 00:48
  • Thanks for the reply Mike. Just haven't had a chance to look at anything yet. Will have to do a bit of reading and get back to you. – Niagaradad Jan 31 '13 at 20:22