{{Short description|Node type in SGML and XML}} A '''processing instruction''' ('''PI''') is an SGML and XML node type, which may occur anywhere in a document, intended to carry instructions to the application.<ref>{{Cite book |last=Stayton |first=Bob |title=DocBook XSL: The Complete Guide |chapter-url=http://www.sagehill.net/docbookxsl/ProcessingInstructions.html |publisher=Sagehill Enterprises |date=September 2007 |chapter=Chapter 9. Customization methods §Processing instructions |isbn=978-0974152134}}</ref><ref>[https://www.w3.org/TR/NOTE-sgml-xml-971215 Comparison of SGML and XML; World Wide Web Consortium Note, 15 December 1997]</ref>

Processing instructions are exposed in the Document Object Model as <code>Node.PROCESSING_INSTRUCTION_NODE</code>, and they can be used in XPath and XQuery with the 'processing-instruction()' command.

== Syntax == An SGML processing instruction is enclosed within <code><?</code> and <code>></code>.<ref>{{cite book |title= SGML and HTML Explained |last= Bryan |first= Martin |publisher= Addison Wesley Longman |year= 1997 |url= https://archive.org/details/sgmlhtmlexplaine0000brya |isbn= 0-201-40394-3 |access-date= 2010-08-18 |url-access= registration }}</ref>

An XML processing instruction is enclosed within <code><?</code> and <code>?></code>, and contains a ''target'' and optionally some content, which is the node value, that cannot contain the sequence <code>?></code>.<ref>{{cite book | title = The Internet encyclopedia, Volume 3 | url = https://archive.org/details/internetencyclop00bidg_359 | url-access = limited | author = Hossein Bidgoli | page = [https://archive.org/details/internetencyclop00bidg_359/page/n911 877] | publisher = John Wiley and Sons | year = 2004 | isbn = 0-471-22203-8}}</ref> <syntaxhighlight lang="xml"><?PITarget PIContent?></syntaxhighlight>

The XML Declaration at the beginning of an XML document (shown below) is another example of a processing instruction,<ref>{{Cite web |title=XML 1.0 - slide "Processing Instructions (PIs)" |url=https://www.w3.org/Consortium/Offices/Presentations/XML1.0/slide30-0.htm |access-date=2023-02-08 |website=www.w3.org}}</ref> however it may not technically be considered one.<ref name="nutshell">{{cite book | title = XML in a nutshell | author = Elliotte Rusty Harold, W. Scott Means | year = 2004 | isbn = 978-0-596-00764-5 | page = 23 }}</ref> <syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8" ?></syntaxhighlight>

== Examples == The most common use of a processing instruction is to request the XML document be rendered using a stylesheet using the 'xml-stylesheet' target, which was standardized in 1999.<ref>{{Cite web|url=https://www.w3.org/TR/xml-stylesheet/|title=Associating Style Sheets with XML documents 1.0 (Second Edition)}}</ref> It can be used for both XSLT and CSS stylesheets. <syntaxhighlight lang="xml"><?xml-stylesheet type="text/xsl" href="style.xsl"?></syntaxhighlight> <syntaxhighlight lang="xml"><?xml-stylesheet type="text/css" href="style.css"?></syntaxhighlight>

The DocBook XSLT stylesheets understand a number of processing instructions to override the default behaviour.<ref>{{Cite web|url=https://docbook.sourceforge.net/release/xsl/current/doc/pi/pi-fo.html|title = Part 2. FO Processing Instruction Reference}}</ref>

A draft specification for Robots exclusion standard rules inside XML documents uses processing instructions.<ref>{{cite web |url=http://www.atrus.org/writings/technical/robots_pi/ |title=Robots Processing Instruction Homepage |accessdate=2010-08-18 |url-status=dead|archiveurl=https://web.archive.org/web/20100921021126/http://www.atrus.org/writings/technical/robots_pi/ |archivedate=2010-09-21 }}</ref>

== References == {{reflist}}

== External links == * [https://www.w3.org/TR/REC-xml/#sec-pi XML specification section: Processing Instructions] * [https://web.archive.org/web/20160303185749/http://www.dpawson.co.uk/xsl/sect2/N6145.html XSLT FAQ: Processing Instructions], Dave Pawson * [https://developer.mozilla.org/en-US/docs/Web/XML/XSLT/Reference/Element/processing-instruction xsl:processing-instruction], Mozilla

Category:XML