定义和用法
XML 是一种在 Web 上共享数据的标记语言,XML 既适用于人类可读,也适用于机器可读。XSL 扩展是 XSL 标准的实现,用于使用 libxslt 库执行 XSTL 转换。
XSLTProcessor::getSecurityPrefs() 函数用于检索以前为当前转换设置的安全首选项值。
语法
XSLTProcessor::getSecurityPrefs();
参数
此函数不接受任何参数。
返回值
此函数返回一个整数值,该值表示当前安全首选项。
PHP 版本
此功能最初在 PHP 版本 5 中引入,并在所有后续版本中有效。
示例
以下是此函数的示例 -
sample.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<Qikepu>
<Title>JavaFX</Title>
<Authors>
<Author>Krishna</Author>
<Author>Rajeev</Author>
</Authors>
<Body>Sample text</Body>
</Qikepu>
sample.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
Title - <xsl:value-of select="/Qikepu/Title"/>
Authors: <xsl:apply-templates select="/Qikepu/Authors/Author"/>
</xsl:template>
<xsl:template match="Author">
- <xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
sample.php:
<?php
// 加载XSL文档
$xsl = new DOMDocument();
$xsl->load("sample.xsl");
// 加载XML文档
$xml = new DOMDocument();
$xml->load("sample.xml");
// 创建XSLTProcessor
$proc = new XSLTProcessor();
// 导入XSL文档
$proc->importStyleSheet($xsl);
// 设置安全首选项
$proc->setSecurityPrefs(XSL_SECPREF_READ_FILE);
$val = $proc->getSecurityPrefs();
print("安全首选项值 :".$val);
// 将样式转换为XML
print($proc->transformToXML($xml));
?>
这将产生以下结果 -
安全首选项值 :2
Title - JavaFX
Authors:
- Krishna
- Rajeev
Title - JavaFX
Authors:
- Krishna
- Rajeev