• PHP Video Tutorials

PHP - XSLTProcessor::setSecurityPrefs() Function



Definition and Usage

XML is a mark-up language to share the data across the web, XML is for both human read-able and machine read-able. XSL extension is an implementation of the XSL standard to perform XSTL transformation using the libxslt library.

The XSLTProcessor::setSecurityPrefs() function is used to set security preferences for the current transform.

Syntax

XSLTProcessor::setSecurityPrefs($pref);

Parameters

Sr.No Parameter & Description
1

pref(Mandatory)

This is an integer value representing the security preference value which can be one of the following:

  • XSL_SECPREF_READ_FILE

  • XSL_SECPREF_WRITE_FILE

  • XSL_SECPREF_CREATE_DIRECTORY

  • XSL_SECPREF_READ_NETWORK

  • XSL_SECPREF_WRITE_NETWORK

  • XSL_SECPREF_NONE

Return Values

This function returns an integer value representing the previous security preferrence.

PHP Version

This function was first introduced in PHP Version 5 and works in all the later versions.

Example

Following is an example of this function −

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));
?>

This will produce following result −

Security Preference Value :2
   Title - JavaFX
   Authors:
   - Krishna
   - Rajeev
php_function_reference.htm
Advertisements