> well Im out of a job so I am sitting around learning XML. It seems like a
> great tool, but I am trying to figure out why I would actually use it?

If you intersting for my experience:

I find xml+xslt useful for offline-site generation tasks,
right now I am making site, and there are folders
content\
  db\
  pages\
  xslt\

in 'db' I store 'pages.xml', 'news.xml' and 'common.xml'

f.e. 'pages.xml' - describe all pages of site:
<?xml version="1.0"?>
<pages>

  <page id="about">
    <name>about</name>
    <descr>more description</descr>
  </page>

  <page id="address">
    <name>address</name>
    <descr>more descritption</descr>
  </page>
...
</pages>

where <name> are going to menu and to page header, <descr> - this is 'title'
for <a>,

'news.xml' - news of site:
<?xml version="1.0"?>
<news>
<news-item>
  <date>01.01.2003</date>
  <text>opening site</text>
</news-item>
</news>

'common.xml' - common information about company (name, year, email, phones
...)
<?xml version="1.0" encoding="windows-1251"?>
<common>
  <year>2003</year>
  <name>Name of company</name>
  <slogan>slogan</slogan>
  <address>
    <line>russia/ekaterinburg</line>
    <line>street/building</line>
    <line>phone</line>
    <line>email</line>
  </address>
  <logo width="200" height="200" src="image.gif" title="title/>
</common>

directory 'pages' store each page as xml file,
f.e. 'about.xml':

<?xml version="1.0"?>
<page-content>
<p img="hands">
paragraph
</p>
</page-content>

then in folder 'xslt' are stored xslt files,
there is 'fp-page.xsl'
an 'site-page.xsl'

first - this is xslt-transformation for First Page (index.html)
second - this is xslt-transformation  for any page of site.

my php script make next - for each page of site
make one xml file, as aggregation of
pages.xml + common.xml + {idPage}.xml
and with this one xml file make site-page.xsl transformation and then save
this as file {idPage}.html

script have template:

<?xml version="1.0">
<page-of-site>
#add_elements_here#
</page-of-site>

and on #add_elements_here# it are placed that xml files,
also script placed tag <pageId>{idPage}</pageId>
where {idPage} - are real page's id ('about', 'address' ...)
by this tag xsl can determine what page he show, and make menu bar with
selected item,
and take from "page-of-site/pages/page[@id = $idPage]/name" (this is XPath)
name of page, for placing description of page.

content may contains any tags, and in xsl there is handlers for them, f.e. I
have 'price.xml',
and I have specific tags for price-list, and price line:

<?xml version="1.0"?>
<page-content>

<p>
<price-list>
  <price file="file1.zip">Things1</price>
  <price file="file2.zip">Things1</price>
</price-list>
</p>

</page-content>

and in site-page.xsl there is handler (tamplate in xslt term.) for this:
<xsl:template match="price-list" mode="content">
  <table border="0" cellpadding="3" cellspacing="3">
  <xsl:for-each select="price">
    <tr>
      <xsl:if test="position() mod 2 != 0">
        <xsl:attribute name="bgcolor">#eeeeee</xsl:attribute>
      </xsl:if>
      <td><xsl:value-of select="."/></td>
      <td><a href="{@file}" target="_blank"><xsl:value-of
select="@file"/></a></td>
    </tr>
  </xsl:for-each>
  </table>
</xsl:template>


hope this helps :)

Ilya

ps: may be in future I make my this project open-source.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to