0

I'm trying to use itstool to translate some attributes from a XML file like this one:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="settings" dlg:left="106" dlg:top="80" dlg:width="283" dlg:height="214" dlg:closeable="true" dlg:moveable="true" dlg:withtitlebar="false">
<dlg:bulletinboard>
<dlg:textfield dlg:id="token" dlg:tab-index="9" dlg:left="48" dlg:top="42" dlg:width="216" dlg:height="40" dlg:multiline="true"/>
<dlg:text dlg:id="label1" dlg:tab-index="0" dlg:left="5" dlg:top="25" dlg:width="40" dlg:height="14" dlg:value="Save path" dlg:align="right" dlg:valign="center"/>
<dlg:text dlg:id="label5" dlg:tab-index="7" dlg:left="5" dlg:top="190" dlg:width="40" dlg:height="14" dlg:value="URL" dlg:align="right" dlg:valign="center"/>
</dlg:bulletinboard>
</dlg:window>

The translatable part here is dlg:value.

For now, the rule I tried, that doesn't select any sentence to translate is:

<?xml version="1.0"?>
<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
  <its:translateRule selector="//dlg:text/@value" translate="yes"/>
</its:rules>

Seems my xpath selector is incorrect here.

EDIT: The problem seems to come from the namespace dlg here.

Emilio Conte
  • 1,105
  • 10
  • 29
  • 1
    The problem is related to how to register namespaces for the evaluation context of your XPath expression. It seems like you are ussing `libxml2` and therefore you could benefit from this answer https://stackoverflow.com/questions/3135175/libxml2-error-with-namespaces-and-xpath – Alejandro Mar 21 '19 at 13:00

2 Answers2

2

Change

//dlg:text/@value

to

//dlg:text/@dlg:value

to account for the namespace on the @value attribute, which is not automatically inherited from the namespace of its element.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
0

Thanks to both @alejandro and @kjhughes this problem is solved.

I had to declare the namespace (used with the colon in dlg:text) in the header of the ITS rule.

<?xml version="1.0"?>
<its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0"
           xmlns:dlg="http://openoffice.org/2000/dialog">
  <its:translateRule selector="//dlg:text/dlg:@value translate="yes"/>
</its:rules>
Emilio Conte
  • 1,105
  • 10
  • 29