Question & Answer
Question
Some DataPower variables I try to access work successfully using XPath and others fail. What is the correct XPath to use?
Cause
Different implementations of nodesets per variable type.
Answer
The answer depends on what variables you are accessing. To make this clear, set up two groupings with two examples.
Group A consists of variables from var://service/*:
When accessing these var://service/* fields, use XPath starting inside the base node.
Use the following example as a guideline:
To get the nodeset aVariables located in context variables:
<xsl:variable select="dp:variable('var://service/aVariables')" name="aVariables"/>
Where the Variable contains a nodeset
<varBase>
<A>"aText"</A>
<B>"bText"</B>
</varBase>
To access the contents of A, you will need to use XPath containing the base tag:
<xsl:message dp:priority="info">
- <xsl:value-of select="$aVariables/varBase/A/text()"/>
</xsl:message>
Group B consists of most var://context/ variables:
When accessing these var://context/ fields, use XPath starting inside the base node.
Use the following example as a guideline:
To get the nodeset bVariables located in context variables:
<xsl:variable select="dp:variable('var://context/bVariables')" name="bVariables"/>
Where the Variable contains a nodeset
<varBase>
<A>"aText"</A>
<B>"bText"</B>
</varBase>
To access the contents of A, you will need to use XPath NOT containing the base tag
<xsl:message dp:priority="info">
<xsl:value-of select="$bVariables/A/text()"/>
</xsl:message>
**Notice for Group B, do not use the base node "varBase" in the XPath value-of function.
Additionally, if it is not mandatory that you use the "value-of" command, you can ensure consistency in node set output by using the "copy-of" command using the following approach:
To get the nodeset cVariables located in service variables use:
<xsl:variable name="cVariables">
<xsl:copy-of select="dp:variable('var://anyDir/cVariables')"/>
</xsl:variable>
This will allow the following command:
<xsl:message dp:priority="info">
<xsl:value-of select="$cVariables/varBase/A/text()"/>
</xsl:message>
to access the contents of a nodeset consistently regardless of its implementation.
Was this topic helpful?
Document Information
More support for:
WebSphere DataPower Integration Appliance XI50
Software version:
4.0.2, 4.0.1, 3.8.2, 5.0.0
Operating system(s):
Firmware
Document number:
206829
Modified date:
15 June 2018
UID
swg21598920