tags:

views:

629

answers:

3

What kind of scenarios can XSL processing instructions be used or applied? When is it good or bad to use them?

Clean slate here, I don't have a good handle on this particular element.

Example from w3schools:

<xsl:processing-instruction name="process-name"> <!-- Content:template --> </xsl:processing-instruction>

A: 

Processing instructions let you insert things like <?php ?> or <?xml ?> into the output code. I myself have never actually found a use for them, so if you don't understand them, you probably don't need 'em. Check the XSLT spec for more details and samples.

Edward Z. Yang
+6  A: 

It's very simple: you'd use <xsl:processing-instruction> if you needed to output a processing instruction in your output XML. If you have no need for PI's in your output, then you don't need the processing-instruction element.

As to why you might need a PI in your output, that depends entirely on what your output will be used for.

I've used them in the past to add <?xml-stylesheet> instructions into my output:

<!-- Link to the stylesheet for people who wander in. -->
<xsl:processing-instruction name='xml-stylesheet'>
        type="text/xsl"
        href="<xsl:value-of select='$stylesheet'/>"
        media="screen"
</xsl:processing-instruction>

produces:

<?xml-stylesheet type="text/xsl" href="http://nedbatchelder.com/rss.xslt" media="screen"?>
Ned Batchelder
+1  A: 

You should use processing instructions when you want to tell the software that processes the XML something about the data it processes. PIs enable you to separate the data and its structure from the commands how the data should be processed. If the software that processes the XML data doesn't know about the PIs, it will ignore them.

chiborg