定義和用法
XML 是一種 mark-up 語言,用於在網絡上共享數據,XML 用於人類 read-able 和機器 read-able。 XSL 擴展是 XSL 標準的實現,用於使用 libxslt 庫執行 XSTL 轉換。
這個XSLTProcessor::setSecurityPrefs()函數用於設置當前轉換的安全首選項。
用法
XSLTProcessor::setSecurityPrefs($pref);
參數
Sr.No | 參數及說明 |
---|---|
1 |
pref(Mandatory) 這是一個表示安全首選項值的整數值,可以是以下值之一:
|
返回值
此函數返回一個整數值,表示先前的安全首選項。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,並且適用於所有後續版本。
示例
下麵是這個函數的一個例子
sample.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<Tutorial>
<Title>JavaFX</Title>
<Authors>
<Author>Krishna</Author>
<Author>Rajeev</Author>
</Authors>
<Body>Sample text</Body>
</Tutorial>
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="/Tutorial/Title"/>
Authors:<xsl:apply-templates select="/Tutorial/Authors/Author"/>
</xsl:template>
<xsl:template match="Author">
- <xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
sample.php:
<?php
//Loading an XSL document
$xsl = new DOMDocument();
$xsl->load("sample.xsl");
//Loading an XML document
$xml = new DOMDocument();
$xml->load("sample.xml");
//Creating an XSLTProcessor
$proc = new XSLTProcessor();
//Importing the XSL document
$proc->importStyleSheet($xsl);
//Setting the security preferences
$proc->setSecurityPrefs(XSL_SECPREF_READ_FILE);
$val = $proc->getSecurityPrefs();
print("Security Preference Value:".$val);
//Transforming the style to XML
print($proc->transformToXML($xml));
?>
這將產生以下結果 -
Security Preference Value:2 Title - JavaFX Authors: - Krishna - Rajeev
相關用法
- PHP XSLTProcessor::setParameter()用法及代碼示例
- PHP XSLTProcessor::transformToDoc()用法及代碼示例
- PHP XSLTProcessor::getSecurityPrefs()用法及代碼示例
- PHP XSLTProcessor::_construct()用法及代碼示例
- PHP XSLTProcessor::importStylesheet()用法及代碼示例
- PHP XSLTProcessor::transformToXml()用法及代碼示例
- PHP XMLReader::getParserProperty()用法及代碼示例
- PHP XMLReader::open()用法及代碼示例
- PHP XMLReader::moveToAttributeNs()用法及代碼示例
- PHP XMLReader::moveToNextAttribute()用法及代碼示例
- PHP XMLWriter startDtdAttlist()用法及代碼示例
- PHP XMLWriter endDtdElement()用法及代碼示例
- PHP XMLReader::moveToAttribute()用法及代碼示例
- PHP XMLReader::next()用法及代碼示例
- PHP XMLReader readOuterXml()用法及代碼示例
- PHP XMLWriter endComment()用法及代碼示例
- PHP XMLReader::setParserProperty()用法及代碼示例
- PHP XMLWriter endDtdAttlist()用法及代碼示例
- PHP XMLReader setRelaxNGSchema()用法及代碼示例
- PHP XMLReader getAttributeNo()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - XSLTProcessor::setSecurityPrefs() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。