Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
XSLT Reference
XSLT Elements
 <xsl:processing-instruction> Elemen...
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
<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
<?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>
Xml
<?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

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>

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker