Skip to main content
13-Aquamarine
November 23, 2017
Solved

How to use XPath expression in Edit APP source in _ufe element?

  • November 23, 2017
  • 2 replies
  • 9097 views

Hello, I want to use _ufe element with universal definition of the colour.
The actual colour will be set in the xml document, e.g. in the <productname> element and his "role" attribute.

I changed the APP source for _ufe by this way:

...
//var color_value = '#0c6979';
var color_value = formating.evaluateXPath("//productname/@role");

 

// Print/PDF properties
style.color = ( color_value )
...

but it doesnลฅ work. Maybe the formating.evaluateXPath function doesn't return a string value?
The attempt with the direct setting of the color (a commented row) works OK.

 

Thanks for help

Jana

Best answer by GarethOakes

I haven't done this for a while, but there always used to be problems with XPath in generated content. Essentially the XPath couldn't properly "see" the document tree when running inside the generated content.

 

There are a couple of solutions:

  1. Store the colour value in a variable and use it later on
  2. Try prepending xml0# to the XPath

For #1, you would have to add a source edit in the root element to save the colour value. e.g. application.variables.myColour = formatting.evaluteXPath("/my/xpath"); Then you can use application.variables.myColour in your generated content source edit.

 

For #2, we're trying to trick APP to "see" the correct XML stream. The in-memory APP document will have a number of streams (headers, footers, and main text). The main text used to be called "xml0" hence the special syntax to direct the XPath to the correct location. e.g. formatting.evaluateXPath("xml0#/my/xpath");

2 replies

16-Pearl
November 24, 2017

You will need to read the FOM documents to get the exact return values, although I think formatting.evaluateXPath() should return a string. The fxDocument (DOM) version of evaluateXPath certainly returns an object though. Your code otherwise looks mostly fine and should do what you're after.

 

Ideas:

  1. Check what the result string is: formatting.write( formatting.evaluteXPath("/whatever") );
  2. Don't use // at the start of an XPath expression. This causes the formatter to search the *entire* document everytime and slows formatting/printing down. Instead you should use a direct path e.g. /document/path/to/productname/@role
13-Aquamarine
November 27, 2017

Hi Gareth, thanks for your tip,  I checked the expression and it returns correct value (e.g. in generated text). But whenever I use it in the APP source edit it doesn't work. The colour of the text is stil in black or it doesn't appear at all.

Jana

 

XPath in APP source.png

13-Aquamarine
November 27, 2017

Hello, I found the different behaviour - whenever I use this _ufe element (with xpath expression) in the common text it works correctly. 

But when I use this same _ufe element  in the "Generated Contents" in the Page Region (and it is area when I need it ๐Ÿ™‚ it doesn't work at all.  

Do you have any idea how to solve it?  Sorry I'm not very skill in FOM/DOM syntaxe ...

 

Thanks  Jana

 

 

16-Pearl
November 27, 2017

I haven't done this for a while, but there always used to be problems with XPath in generated content. Essentially the XPath couldn't properly "see" the document tree when running inside the generated content.

 

There are a couple of solutions:

  1. Store the colour value in a variable and use it later on
  2. Try prepending xml0# to the XPath

For #1, you would have to add a source edit in the root element to save the colour value. e.g. application.variables.myColour = formatting.evaluteXPath("/my/xpath"); Then you can use application.variables.myColour in your generated content source edit.

 

For #2, we're trying to trick APP to "see" the correct XML stream. The in-memory APP document will have a number of streams (headers, footers, and main text). The main text used to be called "xml0" hence the special syntax to direct the XPath to the correct location. e.g. formatting.evaluateXPath("xml0#/my/xpath");