Scott McKenzie
Scott McKenzie

Reputation: 16242

I don't get XSL processing instructions!

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>

Upvotes: 3

Views: 2604

Answers (3)

chiborg
chiborg

Reputation: 28064

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.

Upvotes: 1

Ned Batchelder
Ned Batchelder

Reputation: 375484

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"?>

Upvotes: 6

Edward Z. Yang
Edward Z. Yang

Reputation: 26742

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.

Upvotes: 0

Related Questions