После нескольких часов изучения XSLT я признаю поражение! Мне нужно исправить большое количество файлов перевода .xlf XLIFF, которые были возвращены нам искаженными из безымянного инструмента перевода. В идеале я бы применил к ним XSL-преобразование с помощью пакетного инструмента.
Ниже приведен фрагмент одного из файлов XLIFF:
<body>
<trans-unit id="1" phase-name="pretrans" restype="x-h3">
<source>Adding, Deleting or Modifying Notes in the Call Description</source>
<seg-source>Adding, Deleting or Modifying Notes in the Call Description</seg-source>
<target state="final">Добавление, удаление и изменение примечаний в описании звонка</target>
</trans-unit>
<trans-unit id="2" phase-name="pretrans" restype="x-p">
<source>Description of Fields on RHS</source>
<seg-source>Description of Fields on RHS</seg-source>
<target state="final">Поле описания в правой части</target>
</trans-unit>
<trans-unit id="3" phase-name="pretrans" restype="x-p">
<source>You can add descriptive text notes to a call recording, if you have the appropriate privileges to do so. These notes are visible to all users who have access to the call recording. It is recommended that each user add their initials to the notes to avoid potential confusion.</source>
<seg-source>
<mrk mtype="seg" mid="1">You can add descriptive text notes to a call recording, if you have the appropriate privileges to do so.</mrk>
<mrk mtype="seg" mid="2">These notes are visible to all users who have access to the call recording.</mrk>
<mrk mtype="seg" mid="3">It is recommended that each user add their initials to the notes to avoid potential confusion.</mrk>
</seg-source>
<target state="final">
<mrk mtype="seg" mid="1" /><ph ctype="" id="1"><MadCap:variable name="zoom_userdocs_variables.var_product_name" xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" /></ph> позволяет находить телефонные взаимодействия, содержащие или не содержащие определенные фразы.
<mrk mtype="seg" mid="2" />Каждая речевая метка содержит одну или несколько таких фраз.
<mrk mtype="seg" mid="3" />Ядро <ph ctype="" id="3"><MadCap:variable name="zoom_userdocs_variables.var_product_name" xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" /></ph> индексирует медиафайлы и помечает места вхождения фразы (добавляет к ним метки).
<mrk mtype="seg" mid="4" />Затем нужные медиафайлы можно искать по связанным с ними меткам.
</target>
</trans-unit>
<trans-unit id="4" phase-name="pretrans" restype="x-p">
<source>To add, delete, or modify text in the description field, click inside the description field.</source>
<seg-source>To add, delete, or modify text in the description field, click inside the description field.</seg-source>
<target state="final">Чтобы добавить, удалить или изменить текст в поле описания, щелкните это поле.</target>
</trans-unit>
</body>
Обратите внимание на тег target
в третьем узле trans-unit
. Теги mrk
должны содержать текстовые узлы, которые теперь стали одноуровневыми (по сравнению с более ранним тегом seg-source
, который все еще верен), что портит структуру.
Поэтому я пытаюсь определить любые теги mrk
, которые не содержат текстовых узлов, и вернуть в них следующий текстовый узел.
Вот желаемый результат:
<body>
<trans-unit id="1" phase-name="pretrans" restype="x-h3">
<source>Adding, Deleting or Modifying Notes in the Call Description</source>
<seg-source>Adding, Deleting or Modifying Notes in the Call Description</seg-source>
<target state="final">Добавление, удаление и изменение примечаний в описании звонка</target>
</trans-unit>
<trans-unit id="2" phase-name="pretrans" restype="x-p">
<source>Description of Fields on RHS</source>
<seg-source>Description of Fields on RHS</seg-source>
<target state="final">Поле описания в правой части</target>
</trans-unit>
<trans-unit id="3" phase-name="pretrans" restype="x-p">
<source>You can add descriptive text notes to a call recording, if you have the appropriate privileges to do so. These notes are visible to all users who have access to the call recording. It is recommended that each user add their initials to the notes to avoid potential confusion.</source>
<seg-source>
<mrk mtype="seg" mid="1">You can add descriptive text notes to a call recording, if you have the appropriate privileges to do so.</mrk>
<mrk mtype="seg" mid="2">These notes are visible to all users who have access to the call recording.</mrk>
<mrk mtype="seg" mid="3">It is recommended that each user add their initials to the notes to avoid potential confusion.</mrk>
</seg-source>
<target state="final">
<mrk mtype="seg" mid="1"><ph ctype="" id="1"><MadCap:variable name="zoom_userdocs_variables.var_product_name" xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" /></ph> позволяет находить телефонные взаимодействия, содержащие или не содержащие определенные фразы.</mrk>
<mrk mtype="seg" mid="2">Каждая речевая метка содержит одну или несколько таких фраз.</mrk>
<mrk mtype="seg" mid="3">Ядро <ph ctype="" id="3"><MadCap:variable name="zoom_userdocs_variables.var_product_name" xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" /></ph> индексирует медиафайлы и помечает места вхождения фразы (добавляет к ним метки).</mrk>
<mrk mtype="seg" mid="4">Затем нужные медиафайлы можно искать по связанным с ними меткам.</mrk>
</target>
</trans-unit>
<trans-unit id="4" phase-name="pretrans" restype="x-p">
<source>To add, delete, or modify text in the description field, click inside the description field.</source>
<seg-source>To add, delete, or modify text in the description field, click inside the description field.</seg-source>
<target state="final">Чтобы добавить, удалить или изменить текст в поле описания, щелкните это поле.</target>
</trans-unit>
</body>
Обычно я делаю это на Perl с LibXML или чем-то подобным, но я уверен, что это простая задача для XSLT. Я искал подобное решение, но не смог найти ничего, что могло бы заставить работать.
Еще один момент, на который следует обратить внимание: несмотря на то, что здесь «красиво напечатано», окончательное определение узла body
находится в одной строке.
Спасибо! Я с нетерпением жду возможности узнать что-то новое!
РЕДАКТИРОВАТЬ: Обновлен исходный код выше, чтобы показать дополнительные дочерние теги в элементах <target>
, которые необходимо сохранить. РЕДАКТИРОВАТЬ 2: Добавлен желаемый результат.