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

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

Hi Florin, the .3d file you can create by these steps: from Styler menu - Preview - Print - and then from APP Preview window - File - Save APP File.

 

But despite Gareth's instruction I was not able to find the correct XML stream for the #2 solution, so I used the #1 one. Anyway I'm interested if you will be more successful. If so, post your method.

 

Thanks Jana

Highlighted

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

Hi Gareth,

Followed Jana's instructions to create the .3d file, thank you Jana, and I did poke around with the file looking for all (1657) fdt "name" that could resemble anything close to a stream name but with no success.

 

However, poking around I found something that caught my eye, namely this lines 

$template.primaryStream = 'editorDom0';

$application.variables['_x_primaryStream'] = 'editorDom0';

under the following fdt line, fdt "autoexec",90,"",0,"";;4.

 

I have tried all the following with no success:

formatting.evaluateXPath("count(editorDom0#//doc")

formatting.evaluateXPath("count(editorDom0#/doc")

formatting.evaluateXPath("count(editorDom0//doc")

formatting.evaluateXPath("count(editorDom0/doc")

and that made me think that editorDom0 is not the main stream I am looking for.

 

I still want to get this solution working because more direct (1 step deal) than the second solution which uses two step process. Like I said #1 work just fine.

 

Am I looking at the wrong thing? Any other suggestion or tip?

 

Thank you for help!

 

Have a blessed day!

 

Florin

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

You're correct it is "editorDom0" that is the main stream for Styler-generated the .3D files. I had forgotten. I tested in a standalone .3D file and the syntax formatting.evaluateXPath("editorDom0#/doc"); is the correct one. Perhaps you should raise this with PTC support for further assistance.

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

Hi Gareth,

 

After posting the previous post I kept poking around with the .3d file and I found the following peace of code (changes are obvious Smiley Happy) that confirms that editorDom0 is the main stream:

 

var florin = content.getStream(template.primaryStream);

application.alert("steram name: " + florin.name);

 

which produces the attached result.

 

Now that Gareth confirmed too that editorDom0 is the main stream I will try again to evaluate the XPath, and if does not work I will reach PTC like Gareth suggested.

Jana, you can also try it and see what results are you getting.

 

Thank you for help!

 

Florin

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

Hi Florin,  here is one PTC Article concerning our thema :-)

https://www.ptc.com/en/support/article?n=CS22760

They use this trick:

Change:
if ( formatting.evaluateXPath( "@xml:lang = 'ja'", "1if1" ) != 0 )
To:
if ( formatting.evaluateXPath( "editorDom0#boolean( /RDStyle/ResolvedMap/shopmanualmap/@xml:lang = 'ja')", "1if1" ) != 0 )

 

 

 

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

Hi Jana,

 

Thank you for pointing me in the right direction. After I tried to see what makes sens for me from all that, I came up with following syntax that did work for me.

 

Looking for text() node:

formatting.evaluateXPath("editorDom0#//your/XPath/expression/here/text()", "1if1"));

Using an XPath function:

formatting.evaluateXPath("editorDom0#count(//your/XPath/expression/here)", "1if1"));

Important notes:

 

1. I have tried "editorDom#/your/XPath/expression/here" with one forward slash instead of two forward slashes in the XPath expression and did not work. I know, I know... PTC recommends not to use double forward slashes in a XPath expression because slows down the process, and I kind of agree with that, but this is my finding for now. Gareth, any input?

 

2. Another finding is that the above expressions won't give the expected result without the second parameter "1if1", which to be honest I do not know what it means and/or what it does. Gareth, any input? So do not forget to add "1if1" as a second parameter for evaluateXPath() function. I have looked up in PTC Help, and evaluateXPath() function in fFormatting interface takes only an expression parameter, not two.

 

Thank you again Gareth and Jana to help me get this much more elegant solution to work.

 

Have a blessed day!

 

Florin

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

1. I think the problem is that what you're styling isn't what you expect. Note in that PTC Article there is a /RDStyle/... in the path, that is why you need double-slash so it navigates past that extra element. The problem with // is that it will slow your publishing down - it forces APP to visit every node in the entire document each time that XPath is evaluated.

 

2. I have no idea about "1if1", this is the first time I've ever seen that syntax.