I'm not sure I can give you a full, technically correct explanation as far as Presto goes. But I can answer it (sort of).
The second expression (where you don't use string):
{ $XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2/text() }
is in a dynamic mashup expression (the braces). The evaluation of dynamic mashup expressions is processed somewhat differently (not just as a simple XPath expression). Your expression in <display> however, is a simple XPath expression.
That said, I'm not sure why you need text() for <display> or for the dynamic mashup expression in <constructor>. Since the nodes identified in both XPath expressions have simple content (no further markup), you don't really need text() to extract just the text content. Either of these expressions should work and give you the same results:
<display message="field2:" expr="$myNode/ahc:field2" />
and
<field3>{ $XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2}</field3>
The only reason to use text(), in most cases, is in situations where the content of a node is mixed (text and markup children). For example if your XPath points to this html paragraph:
<p>A paragraph with <b>inline</b> markup</p>.
If you don't need the descendant markup, text() will pull out only the simple content of the node and all descendants, removing the additional markup.
Sara, technical writer/jackbe
Hi Sara,
thanks for getting back to me on this one. I actually get different outputs if I append the text() function to access the text node.
For example:
<display message="field2:" expr="$myNode/ahc:field2" />
yields: field2: <ahc:field2 xmlns:ahc="http://www.ahc.co.nz/1_0/IJF">a</ahc:field2> and
<constructor outputvariable="$testOutput">
<topnode>
<field3>{ $XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2 }</field3>
</topnode>
</constructor>
yields:
<topnode>
<field3>
<ahc:field2 xmlns:ahc="http://www.ahc.co.nz/1_0/IJF">a</ahc:field2>
</field3>
</topnode>
but what I actually wanted was: field2: a and <field3>a</field3> which I can achieve if I use the the syntax that I posted initially.
It's no big deal, I was just curious as to why I needed the string() in the <display> markup and now I've solved my problem I'll just remember for next time.
Cheers, Innes



Hi mashers,
Someone will probably tell me that this is obvious, but this little problem has driven me nuts for the last couple of days. I finally figured out how to solve it, but the reason why eludes me and I hate a mystery.
Can anyone explain why when I use <display> for diagnostics I can only access the text node if it is wrapped in a string() function?
For example:
<display message="myValue: " expr="$myNode/ahc:field2/string(text())" /> will display the text for the node but
<display message="myValue: " expr="$myNode/ahc:field2/text() />" will not,
and yet in the following <constructor> statement I don't need to wrap a string() around the text() function to get the element content.
<constructor outputvariable="$testOutput">
<topnode>
<field3>{ $XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2/text() }</field3>
</topnode>
</constructor>
in case it is important here was the whole emml file:
<mashup xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jackbe.com/2008-03-01/EMMLSchema/ ../src/schemas/EMMLSpec.xsd"
xmlns="http://www.jackbe.com/2008-03-01/EMMLSchema"
xmlns:macro="http://www.jackbe.com/2008-03-01/EMMLMacro"
xmlns:ahc="http://www.ahc.co.nz/1_0/IJF"
name = "test2">
<output name="testOutput" type="document"></output>
<variables>
<variable name="XMLSet" type="document"></variable>
</variables>
<constructor outputvariable="$XMLSet">
<ahc:somenodes>
<ahc:anode>
<ahc:field1>1</ahc:field1>
<ahc:field2>a</ahc:field2>
</ahc:anode>
<ahc:anode>
<ahc:field1>2</ahc:field1>
<ahc:field2>b</ahc:field2>
</ahc:anode>
<ahc:anode>
<ahc:field1>3</ahc:field1>
<ahc:field2>c</ahc:field2>
</ahc:anode>
</ahc:somenodes>
</constructor>
<foreach variable="myNode" items="$XMLSet/ahc:somenodes/ahc:anode">
<display message="field2:" expr="$myNode/ahc:field2/string(text())" />
</foreach>
<display message="field2 in anode[1]: " expr="$XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2/string(text())" />
<constructor outputvariable="$testOutput">
<topnode>
<field3>{ $XMLSet/ahc:somenodes/ahc:anode[1]/ahc:field2/text() }</field3>
</topnode>
</constructor>
</mashup>