sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
SEWC's Avatar

best way to do this?


Question posted by: SEWC (Newbie) on August 21st, 2008 11:56 PM
I have many pages with a unique short paragraph description for that page. Is it possible to have one text file for all of these paragraphs, and that each page could grab the appropriate paragraph from this one text file? I thought xml or AJAX might be the answer, but I'm not sure. I'd rather not have one text file for each html/php/whatever page, as that kind of defeats the intention of one easy file to edit. I've been looking for something like this for days, and have done lots of research, but can't quite come up with this method. And, of course, the text that shows up on the page needs to be searchable.
I'm open to any solution, and would welcome any suggestions.

Thanks in advance.
5 Answers Posted
Dormilich's Avatar
Dormilich August 22nd, 2008 01:51 PM
Expert - 596 Posts
#2: Re: best way to do this?

this depends on how you build each page.
You can insert via php an paragraph from one xml file using xslt (this is how I do it on my website). but I'm not familiar with searches.
SEWC's Avatar
SEWC August 22nd, 2008 02:44 PM
Newbie - 3 Posts
#3: Re: best way to do this?

I was initially thinking xml and DOM parser.
XML Text file would be something like:
<page1Paragraph>This is the text that goes on page 1.</page1Paragraph>
<page2Paragraph>This is the text that goes on page 2.</page2Paragraph>
<page3Paragraph>This is the text that goes on page 3.</page3Paragraph>
etc.

Then have a loadXMLDoc function on each page with a <pageXParagraph>div.
I can't get it to work, though, and wondered if anyone had any ideas on this, or perhaps a better way to do it.

Everyone on this board seems sharp and well-rounded, so it looked like the best place to ask.

I found this script, but, while it worked locally, oddly, it didn't work when I tried it on a server. It's exactly what I need. (Except, of course, that it doesn't quite work.)
http://www.tek-tips.com/viewthread....1443973&page=10

By searchable, I simply mean that I want the text embedded in the html, not like an iframe or Spry.

Thanks for your help.
Dormilich's Avatar
Dormilich August 23rd, 2008 03:23 AM
Expert - 596 Posts
#4: Re: best way to do this?

have you any means to find out why the script does not work on the server? (personally, I use the Firebug plugin for Firefox) My guess is, that maybe the XML file is not loaded correctly.
SEWC's Avatar
SEWC August 23rd, 2008 05:04 PM
Newbie - 3 Posts
#5: Re: best way to do this?

It works locally only in Safari, not even in Firefox. Doesn't work on anything from the server. I'm ready to give up.
Doesn't anyone have some scripts that do this? DOM Parser, HTTPRequest? My pages are php.

Thanks!
Dormilich's Avatar
Dormilich August 23rd, 2008 08:13 PM
Expert - 596 Posts
#6: Re: best way to do this?

Ok, one possible solution using XSL:

part 1 - designing the xml file

this strongly depends on how you identify each page. You said you have quite a lot pages I recomment identification by id attribute (or similar).
Expand|Select|Wrap|Line Numbers
  1. <!-- DTD here if needed -->
  2. <desc>
  3.   <page id="1"><!-- description goes here --></page>
  4. ...
  5. </desc>

of course you can use any id value you like (e.g. numbers, characters, random strings)

part 2 - writing xsl

you get the <page> element you want by selecting the appropriate id.

Expand|Select|Wrap|Line Numbers
  1. <!-- xsl header declaration -->
  2. <xsl:param name="page">default value</xsl:param>
  3.  
  4. <xsl:template match="/">
  5.   <p><xsl:value-of select="child::page[@id=$page]" /></p>
  6. </xsl:template>


note: you have to set the <xsl:param> through php to get the desired result. the default is only a fallback.

part 3 - putting it all together

important note: as I'm using php4, xsl processing is quite different to php5, if you're using that please look up the xsl processing on www.php.net.
this function combines the xml and xsl and returns the result thereof. you might want to check, if there was an error or not.
Expand|Select|Wrap|Line Numbers
  1. $handle = xslt_create();
  2. echo xslt_process($handle, $yourXML, $yourXSL, NULL, array(), array('page' => $pageid));
  3. xslt_free($handle);

the thing you have to develop is how each site is connected to the ids in the xml file
Reply
Not the answer you were looking for? Post your question . . .
197,045 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,045 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top XML Contributors