Env - SetXmlVar

Page / - last modified by Outhman Moustaghfir on 2024/06/20 12:11

SetXmlVar

last modified by Outhman Moustaghfir

on 2024/06/20 12:11

Table of Contents

Overview

Parameters

Usage

Retrieving Variable Values

Note

Conclusion

Overview

The SetXmlVar function is used to define and set xml as variables within a scenario. Variables can be classified as either global or local, each serving distinct purposes within the execution of scenarios.

SetXmlVar(variable_name, value, global=False)

variable_name: The name of the variable to be set.

value: The value to assign to the variable.

global (optional): A boolean flag indicating whether the variable should be global. Defaults to False.

Parameters

variable_name: (Type: string) The unique identifier for the variable.

value: (Type: any) The value to assign to the variable.

global: (Type: boolean, Optional) Specifies whether the variable is global or local. Defaults to False.

Usage

Example 1: Setting a Local Variable

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ixf="http://www.ixPath.com/Function"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ix="localFunction"
xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
<xsl:output method="xml" indent="yes"></xsl:output>
<!-- Beginning of the Translation -->
<xsl:template match="/">
<xsl:variable name="varrr">
<Tracking>
<MyTrk>
<Num>2023</Num>
</MyTrk>
<MyTrk>
<Num>2024</Num>
</MyTrk>
</Tracking>
</xsl:variable>
<ixDOC>
<xsl:value-of select="ixf:SetXmlVar('xmlVar',$varrr)"></xsl:value-of>
</ixDOC>
</xsl:template>
</xsl:stylesheet>

Retrieving Variable Values

To retrieve the value of a variable, use the GetXmlVar function:

<xsl:value-of select="ixf:GetXmlVar('variable_name')"></xsl:value-of>

variable_name: The name of the variable whose value you want to retrieve as an xml.

Note

If global is set to true, the variable will be considered global. Omitting the global parameter or setting it to false makes the variable local.

Conclusion

The SetXmlVar function provides a flexible way to manage xml as variables within scenarios, allowing you to control their scope and access them as needed.