PHP头条
热点:

php–使用xslt获取属性节点并打印不同的值










如何获取tab的dim属性的值并使用xslt.means取出不同的值它将打印30,40,70

解决方法:

要选择不同的属性值,可以使用此XPath:

/page/tab[not(@dim=preceding-sibling::tab/@dim)]/@dim

可能的XSLT模板











到transform the source document with the stylesheet in PHP,您可以使用:

$xml = new DOMDocument;
$xml->load('collection.xml');
$xsl = new DOMDocument;
$xsl->load('collection.xsl');
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);

这将在输出中给出30,40,70.

只需执行以下操作即可在没有XSLT的情况下实现相同的目标:

$page = simplexml_load_file('NewFile.xml');
$dims = $page->xpath('/page/tab[not(@dim=preceding-sibling::tab/@dim)]/@dim');
$dims = array_map('strval', $dims);
sort($dims);
echo implode(',', $dims);

另见

> http://schlitt.info/opensource/blog/0704_xpath.html
> How do I generate a comma-separated list with XSLT/XPath?
> XPath 1.0 select distinct attribute of siblings


www.phpzy.comtrue/phpzx/48629.htmlTechArticlephp–使用xslt获取属性节点并打印不同的值 如何获取tab的dim属性的值并使用xslt.means取出不同的值它将打印30,40,70 解决方法: 要选择不同的属性值,可以使用此XPath: /page/tab[not(@dim=precedin...

相关文章

PHP之友评论

今天推荐