Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
<xsl:processing-instruction> Element

<xsl:processing-instruction> Element

Generates a processing instruction node in the output.

<xsl:processing-instruction
  name = "pi-name">
</xsl: processing-instruction>

name
Required. The NCName of the processing instruction.

The <xsl:processing-instruction> element generates a processing instruction node in the output. The name is indicated by the name attribute. The content of the element provides the rest of the processing instruction.

The XML declaration is not a processing instruction, and should be generated by setting attributes on an <xsl:output> element.

This example shows a template that generates the XML declaration and a style sheet processing instruction in the output.

XML File (customers.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="pi.xsl" ?>
<customers>
<customer>
   <name>James Smith</name>
   <address>123 Elm St.</address>
   <phone>(123) 456-7890</phone>
</customer>
<customer>
   <name>Amy Jones</name>
   <address>456 Oak Ave.</address>
   <phone>(156) 789-0123</phone>
</customer>
</customers>

XSLT File (pi.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:output method='xml' version='1.0'/>
<xsl:template match="/">
  <xsl:processing-instruction name="xml-stylesheet">
  <xsl:text>type="text/xsl" href="style.xsl"</xsl:text>
  </xsl:processing-instruction>
  <xsl:apply-templates />
</xsl:template>

  <xsl:template match="@* | *">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template></xsl:stylesheet>

Try It!

  1. Copy the code above and save it in appropriate files on your local drive.

  2. Run the example, using the msxsl.exe utility—available at www.microsoft.com/downloads/—from the command prompt, as follows:

    msxsl customers.xml pi.xsl -o new-cust.xml

Output

The result of this transformation is the same XML file with a new style sheet embedded in it. The output file, new-cust.xml, should look as follows:

<?xml version="1.0" encoding="UTF-16"?>

<?xml-stylesheet type="text/xsl" href="style.xsl" ?>

<customers>

<customer>

<name>James Smith</name>

<address>123 Elm St.</address>

<phone>(123) 456-7890</phone>

</customer>

<customer>

<name>Amy Jones</name>

<address>456 Oak Ave.</address>

<phone>(156) 789-0123</phone>

</customer>

</customers>




Build Date:

2012-08-02
Show:
© 2015 Microsoft