It is planned that the first version, which can be called stable and completely usable, will appear before the end of the year.
<?php function replace($author_id, $category_id) { $xml = new DOMDocument(); if(!$xml->load('/var/www/html/mywebsite/xml/library.xml')) { throw new Exception('Error loading XML file'); } $xpath = new DOMXPath($xml); foreach($xpath->query('/books/book') as $book) { $price = $xpath->query('price', $book); if($price->length != 1) { throw new Exception('Node "price" should be unique for the book'); } $price->item[0]->nodeValue = 0; $currency = $price->getAttribute('currency'); if($currency) { $book->setAttribute('currency', strtolower($currency)); } else { throw new Exception('Attribute "currency" not found'); } $book->setAttribute('author_id', $author_id); $book->setAttribute('category_id', $category_id); } } ?>
<?php function replace($author_id, $category_id) { $xml = xml::load('/xml/library.xml'); foreach($xml->query('/books/book') as $book) { $book['price'] = 0; $book['price/@currency'] = strtolower($book['price/@currency']); $book['@author_id'] = $author_id; $book['@category_id'] = $category_id; } } ?>
::get()
, so you can easily integrate with third-party libraries working through native PHP DOM objects.
www:paginate($page, $count, $size)
$page
is the current page.
$count
- the total number of pages.
$size
- paginator size.
current
attribute. On the first page there will be no <previous />
node, on the last page there will be <next />
nodes.
www:paginate(15, 85, 10)
will return the following XML:
<pages> <previous>14</previous> <page>10</page> <page>11</page> <page>12</page> <page>13</page> <page>14</page> <page current="current">15</page> <page>16</page> <page>17</page> <page>18</page> <page>19</page> <next>16</next> </pages>
<xsl:template match="/"> <xsl:apply-templates select="www:paginate(15, 85, 10)/pages/*" /> </xsl:template> <xsl:template match="previous"> <a href="/page/{.}/" class="page">← Previous</a> </xsl:template> <xsl:template match="next"> <a href="/page/{.}/" class="page">Next →</a> </xsl:template> <xsl:template match="page[@current]"> <span class="page current"><xsl:value-of select="." /></span> </xsl:template> <xsl:template match="page"> <a href="/page/{.}/" class="page"><xsl:value-of select="." /></a> </xsl:template>
www:xslt
XSL extension can be cached into files. To do this, add the attribute cache="true"
. There are also two optional attributes cache-args
and cache-lifetime
, the first of which allows you to transfer a list of simple parameters to the cached block, and the second to limit the lifetime of the cached data. Usage example:
<www:xslt xsl="/books.xsl" xml="book:list(author_id -> {$author_id})" args="page -> {$page}, count -> 10" cache="true" cache-args="domain -> '{$domain}'" cache-lifetime="600" />
www:xquery
XSL extension:
<div> <h1>External Resources</h1> <www:xquery src="/tpl/links.xq" /> </div>
$www = www::create('en', 'us'); $www->register_xsl('http://supermarkup.com/about', 'sm', 'block', function($node) { $xml = new xml(); foreach($node->children() as $child) { $xml->append($xml->import($child)); } foreach($xml->query('//text()') as $text) { $parent = $text->parent(); $parent->append(supermarkup($text->value())); $parent->remove($text); } return $xml; });
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns:www="https://github.com/nyan-cat/easyweb" xmlns:sm="http://supermarkup.com/about" exclude-result-prefixes="php www sm"> <xsl:template match="/"> <sm:block> <xsl:copy-of select="message" /> </sm:block> </xsl:template> </xsl:stylesheet>
<procedure name="geoip:record" datasource="geoip" method="record" root="record"> <param name="host" type="string" /> </procedure>
www:query
XPath extension, or from PHP via an Easyweb instance. Call example:
$record = $www->query('geoip:record', array ( 'host' => $www->variable('user:ip') ));
<?xml version="1.0"?> <record> <country> <alpha2>US</alpha2> <alpha3>USA</alpha3> <name>United States</name> </country> <region>NC</region> <city>Charlotte</city> <latitude>35.206001281738</latitude> <longitude>-80.829002380371</longitude> </record>
<datasource name="metadata" type="solr" server="localhost" port="8080" url="/solr/" username="admin" password="samplepassword" /> <!-- ... --> <procedure name="guestbook:add" datasource="guestbook" core="guestbook" method="add"> <param name="author_id" type="natural" /> <param name="message" type="author" /> <param name="host" type="ipv4" /> </procedure> <!-- ... --> <procedure name="guestbook:list" datasource="guestbook" core="guestbook" method="query" root="messages" item="message"> *:* </procedure>
Source: https://habr.com/ru/post/164397/