cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Level 7

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

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

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Level 12

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

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");

16 REPLIES
Level 12

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

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
Level 7

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

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

Level 7

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

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

 

 

Level 12

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

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");

Level 7

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

Hi Gareth, many thanks,  #1 solution (application.variables) works perfect for the Generated Content in the title page!

 

I tried to test also your #2 tip by using XML streams.

But I donť know how to find out the correct number of the stream for the using in my XPath expression?

 

J.

Level 12

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

Yes this isn't particularly obvious or easy to get to. The most straightforward way would be to use the Styler option that lets you save a .3D file to disk. The .3D file is an intermediate format that contains the complete set of content and styling used to produce the PDF. You can then open the .3D file in a text editor (e.g. Notepad++) and find all the stream definitions (fdt "streamName"). If you spend five minutes poking around in that file it should be pretty obvious which one is the main content stream.

Level 8

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

Hi Gareth,

 

I also ran into same situation as Jana. I have used solution #1 and did work, but I would like to try solution #2 as well. The difference is that i would like to use an XPath function like count() within the XPath expression.

 

I have tried the following with no success:

 

var NoPubs = formatting.evaluateXPath("count(xml0#//chghistory/chginfo) + 1");

and

var NoPubs = formatting.evaluateXPath("count(xml0#/chghistory/chginfo) + 1");

 

document root is <doc>, and the absolute path to the nodeset  is doc/docwp/front/idinfo.

What i am doing wrong?

I would appreciate any help.

 

Florin

Level 12

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

Start with a simple expression and grow from there.

 

formatting.evaluateXPath("count(/doc)"); // should return "1", unless your XPath context is not the main stream

formatting.evaluateXPath("count(xml0#/doc)"); // should return "1", forcing XPath context to main stream

 

If neither of the above are working then you will need to figure out what the main stream name is, by opening a .3D file and inspecting with a text editor. Sorry but I haven't done this for a few years now so I'm not up to date on exact stream names and things.

 

Level 8

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

Hi Gareth,

 

It did not work, most likely because the xml0# is not the main stream name.

I never used (create, access, or access) a .3d file.

 

Any help to get #2 working is appreciated. like I said #1 works just fine but now you made me curios how #2 can be implemented.

 

Thank you for help!

 

Florin