ITS and XPath

26 views
Skip to first unread message

Michel Farhi-chevillard

unread,
Feb 23, 2024, 4:41:36 PMFeb 23
to okapi-users
Hi, 

I would like to set my localization note to a specific node if it exists, or another node if the first node doesn't exist.

So, I need to create an XPath expression for  locNotePointer that would do that.

According to what I read at https://stackoverflow.com/questions/27234421/xpath-expression-which-selects-nodea-if-it-exists-but-otherwise-fall-back-to-no, I would need XPath 2.0 for that.

Does ITS 2.0 support XPath 2.0 or only XPath 1.0? The documentation only talks about XPath 1.0, but I was wondering.

To illustrate what I want to do, here is a sample of my XML file:

   </entry>
   <entry key="PluginActionLaunchExecutable" needsReview="no">
      <loc>Launch</loc>
   </entry>
   <entry key="SolverProblemPackageNameAndVersionFormat" needsReview="no">
      <loc>{0} ({1})</loc>
      <comment>0=name, either display name or package name; 1=version, either display version or package version</comment>
   </entry>


For the first entry, since <comment> isn't there, I want to set the loc note to @key.  For the second entry, since <comment> exists, I would like to set it to that comment.

Thanks

Chase Tingley

unread,
Feb 23, 2024, 5:21:38 PMFeb 23
to Michel Farhi-chevillard, okapi-users
ITS 2.0 only supports XPath 1.0 -- this is part of the spec.

The filter's XPath implementation is based on Saxon-HE, which supports XPath all the way up to 3.1, but accesses it through a JAXP wrapper which only supports XPath 1.0.  I have not tried putting XPath 2.0 rules into an ITS configuration -- it would be a good experiment.

--
You received this message because you are subscribed to the Google Groups "okapi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to okapi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/okapi-users/91b2f07f-c344-49f8-8f15-55213c1bb948n%40googlegroups.com.

Michel Farhi-chevillard

unread,
Feb 23, 2024, 5:33:09 PMFeb 23
to okapi-users
Thanks, so far, I am not making this work, so I think I'm going to drop this idea...   Too bad!
I keep getting errors like:

Bad XPath expression in pointer '(../@key,../comment)[1]:
javax.xml.transform.TransformerException: Expected ), but found: ,'.

Álvaro Mira del Amo

unread,
Feb 26, 2024, 7:44:12 PMFeb 26
to okapi-users
Hi Michel,
It may not be perfect, but given an all or nothing approach, maybe you can consider using a concatenation of both (e.g. "concat(../@key, '|', ../comment)") using xpath 1, so when there is a comment you will get it on top of getting the @key attribute. Again, not perfect because it is not OR, but at least you add plenty of information to your localization notes.

Michel Farhi-chevillard

unread,
Feb 26, 2024, 8:47:08 PMFeb 26
to okapi-users
That's a technique I use to set the <resname> using itsx:idValue and a concatenation, but it's not available for the localization <note> element, for which you have to set the locNotePointer. 
Unless of course you can show me otherwise, maybe I missed something obvious...

Thanks!

Álvaro Mira del Amo

unread,
Feb 27, 2024, 6:03:43 PMFeb 27
to okapi-users
Fair point, Michel.
What if you create two rules for notes, the first one pointing to the @key attribute, the second one to the comment node?
See a couple of screenshots using those two rules in that order and using the same xml content structure you shared with a few additional nodes.
xml_content.png

Álvaro Mira del Amo

unread,
Feb 27, 2024, 6:05:02 PMFeb 27
to okapi-users
Attaching the second screenshot, which was not uploaded to the previous message. Apologies for the additional message.
xliff_content.png
Reply all
Reply to author
Forward
0 new messages