processing-instruction
A processing-instruction statement injects a processing instruction into the output docu- ment where the
statement is placed..
Syntax
<processing-instruction> ::= “processing-instruction” <quote> <name> <quote> “{”
( <block template> )+
“}”
Options
name
|
The name of the processing instruction. |
Elements
A set of block statements that should be included in the processing instruction.
Examples
For example, a stylesheet that iterates through a set of <loop> elements in a file and output the result
together with a processing instruction that generates an index number of the elements.
stylesheet {
version "1.0"
match using "/root" {
element "list" {
foreach "loop" {
element "div" {
processing-instruction "loop" {
value "concat( '[', position(), ']' )"
}
value "concat( 'Entry [', ., ':', position(), ']' )"
}
}
}
}
}
This compiles to
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<template match="/root">
<element name="list">
<for-each select="loop">
<element name="div">
<processing-instruction name="loop">
<value-of select="concat('[', position(), ']')"/>
</processing-instruction>
<value-of select="concat('Entry [', ., ':', position(), ']')"/>
</element>
</for-each>
</element>
</template>
</stylesheet>
To see the result of the above, consider a scrap of XML
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml version="1.0" encoding="UTF-8"?>
<root>
<loop>A</loop>
<loop>B</loop>
<loop>C</loop>
<loop>D</loop>
</root>
Running the script would produce
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
<?xml version="1.0" encoding="UTF-8"?>
<list>
<div><?loop [1]?>Entry [A:1]</div>
<div><?loop [2]?>Entry [B:2]</div>
<div><?loop [3]?>Entry [C:3]</div>
<div><?loop [4]?>Entry [D:4]</div>
</list>
Errors
No opening bracket
element "div" {
processing-instruction "loop"
value "concat( '[', position(), ']' )"
}
value "concat( 'Entry [', ., ':', position(), ']' )"
will give the errors
**** (104) Missing "{" in line 9
Insert bracket.
Leaving out the name
processing-instruction {
value "concat( '[', position(), ']' )"
}
will give
**** (115) Expected name after "processing-instruction" in line 8
Insert name.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.