If you are using an XML fragment as replacement instruction for the pc:ReplaceVariables directive or for the strings:ReplaceVariables() function, you can have variable elements in this XML string.
This allows you to pass input parameters to the replacement routine.
Express the variable elements as variable references. Do an extra call to pc:assign-nodeset with Attribute Value Template (AVT) curly bracket. This causes the variable references to be resolved before the XML is passed to the replacement routine.
Example 1
This example shows input parameters passed to the pc:ReplaceVariables directive.
<pc:assign-default myparameter1="my_replacement1"/>
<pc:assign-default myparameter2="my_replacement2"/>
<pc:assign-nodeset input="input.xml"/>
<pc:assign-nodeset replacements="{rs}">
<rs>
<r NAME="replace_this_string1" VALUE="{$myparameter1}"/>
<r NAME="replace_this_string2" VALUE="{$myparameter2}"/>
</rs>
</pc:assign-nodeset>
<pc:WriteFile filepath="output.xml" disable-output-escaping="yes">
<pc:ReplaceVariables txt="{$input}" select="$replacements"/>
</pc:WriteFile>
|
Example 2
This example is equivalent to Example 1. This example shows input parameters passed to the strings:ReplaceVariables() function.
<pc:assign-var-default myparameter1="my_replacement1"/>
<pc:assign-var-default myparameter2="my_replacement2"/>
<pc:assign-nodeset input="input.xml"/>
<pc:assign-nodeset replacements="{rs}">
<rs>
<r NAME="replace_this_string1" VALUE="{$myparameter1}"/>
<r NAME="replace_this_string2" VALUE="{$myparameter2}"/>
</rs>
</pc:assign-nodeset>
<pc:assign-nodeset replaced="{strings:ReplaceVariables($input, $replacements)}"/>
<pc:WriteFile filepath="output.xml">
<pc:copy-of select="$replaced"/>
</pc:WriteFile>
|
See also
pc:ReplaceVariables
|