PHP - XSLTProcessor::getSecurityPrefs() 函式



定義和用法

XML 是一種用於在網路上共享資料的標記語言,XML 既可供人類閱讀,也可供機器閱讀。XSL 擴充套件是 XSL 標準的實現,它使用 libxslt 庫執行 XSLT 轉換。

XSLTProcessor::getSecurityPrefs() 函式用於檢索當前轉換先前設定的安全首選項值。

語法

XSLTProcessor::getSecurityPrefs();

引數

此函式不接受任何引數。

返回值

此函式返回一個整數,表示當前的安全首選項。

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_function_reference.htm
廣告