Я запускаю следующее преобразование:
java -jar saxon9.jar -it:main -xsl:my.xsl dir="ca-ES"
«ca-ES» содержит файлы XLIFF со следующим корневым элементом:
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cba="http://www.softcon.de/XML-schema/de.softcon.cba.itembuilder.xliff-supplement"
version="1.1"
xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff-core-1.1.xsd">
Преобразование использует идентичные файлы из вторичной входной папки и создает столько структурно идентичных файлов, сколько находится во входной папке.
Если я удалю первое пространство имен (т. е. xmlns="urn:oasis:names:tc:xliff:document:1.1"
) из корня (т. е. xliff
), то преобразование работает как шарм. Однако, если я оставлю это, то это не сработает.
Часть, которая не работает, — это шаблон, который соответствует source
в первичном входном файле и заменяет его на source
из вторичного входного файла):
<xsl:copy-of select="key('ref', ../@id, doc($secondary-input))/source" />
Под неработающим я подразумеваю, что source
из основного входного файла находится на выходе, а не ожидаемый узел source
из вторичного ввода. Таким образом, кажется, что пространство имен мешает сопоставлению.
В поисках решений я попытался добавить атрибут xpath-default-namespace
в элемент документа таблицы стилей:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="urn:oasis:names:tc:xliff:document:1.1"
version="2.0">
но тогда узел source
из основного ввода сохраняется в выводе (то есть он не заменяется узлом из вторичного ввода).
Я также пытался добавить этот префикс, а затем использовать его в таблице стилей для сопоставления узлов (например, match="xlf:source"
), но тогда в выводе вообще нет узла source
:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlf="urn:oasis:names:tc:xliff:document:1.1"
version="2.0">
Буду признателен за несколько советов.
Я использую XSLT 2.0 и saxonb9-1-0-8j.
ОБНОВЛЕНИЕ
Добавляем один образец основного входного файла (с именем ca-ES_blabla.xlf
, взятый из папки ca-ES):
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cba="http://www.softcon.de/XML-schema/de.softcon.cba.itembuilder.xliff-supplement" version="1.1" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff-core-1.1.xsd">
<file datatype="html" original="project.properties" source-language="ca">
<body>
<trans-unit id="MDSD_0" xml:space="default">
<source>Gestiona les adreces d'interès</source>
<target>Gestiona les adreces d'interès</target>
<context-group name="era">
<context context-type="x-property-id">bookmarkHeaderText</context>
</context-group>
</trans-unit>
<trans-unit id="7" xml:space="default">
<source><b>Sempre rebrà un avís quan arribi a un punt a partir del qual no pugui tornar enrere.</b><br /></source>
<target><b>Sempre rebrà un avís quan arribi a un punt a partir del qual no pugui tornar enrere.</b><br /></target>
<prop-group name="item_description">
<prop prop-type="x-inquiry-nr">4</prop>
<prop prop-type="x-type">question</prop>
</prop-group>
</trans-unit>
</body>
</file>
<!-- the xliff document might contain several <file> nodes -->
</xliff>
один образец вторичного входного файла (с именем en-GB_blabla.xlf
, взятый из папки en-GB):
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cba="http://www.softcon.de/XML-schema/de.softcon.cba.itembuilder.xliff-supplement" version="1.1" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.1 xliff-core-1.1.xsd">
<file datatype="html" original="project.properties" source-language="en-GB">
<body>
<trans-unit id="MDSD_0" xml:space="default">
<source>Manage your bookmarks</source>
<target>Manage your bookmarks</target>
<context-group name="era">
<context context-type="x-property-id">bookmarkHeaderText</context>
</context-group>
</trans-unit>
<trans-unit id="7" xml:space="default">
<source><b>You will always receive a warning before reaching a point where you cannot go back.</b><br /></source>
<target><b>You will always receive a warning before reaching a point where you cannot go back.</b><br /></target>
<prop-group name="item_description">
<prop prop-type="x-inquiry-nr">4</prop>
<prop prop-type="x-type">question</prop>
</prop-group>
</trans-unit>
</body>
</file>
<!-- the xliff document might contain several <file> nodes -->
</xliff>
и таблица стилей:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="urn:oasis:names:tc:xliff:document:1.1"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
<!-- run as:
$> java -jar saxon9.jar -it:main -xsl:this_stylesheet.xsl dir="xx-XX" -->
<!-- this captures the folder parameter given in the call -->
<xsl:param name="dir" select="dir" />
<!-- this template iterates through the files in the input folder -->
<xsl:template name="main">
<xsl:variable name="input-files" select="concat($dir, '?select=*.xlf')" />
<xsl:apply-templates select="collection($input-files)"/>
</xsl:template>
<!-- this template defines the name of the output folder and files -->
<xsl:template match="/">
<xsl:variable name="output-name" select="replace(
tokenize(document-uri(/), '/')[last()],
'(.+)\.xlf',
'$1_bilingual.xlf'
)"/>
<xsl:result-document href="{$dir}_output/{$output-name}">
<xsl:apply-templates/>
</xsl:result-document>
</xsl:template>
<!-- this template fetches the source from the English files -->
<xsl:key name="ref" match="trans-unit" use="@id"/>
<xsl:template match="source">
<xsl:variable name="input-uri" select="document-uri(/)" />
<!-- <xsl:message><xsl:value-of select="$input-uri" /></xsl:message> -->
<xsl:variable name="secondary-input" select="replace($input-uri, $dir, 'en-GB')"/>
<xsl:copy-of select="key('ref', ../@id, doc($secondary-input))/source" />
</xsl:template>
<!-- this part generates the output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
source
. - person msoutopico   schedule 19.06.2017xpath-default-namespace="urn:oasis:names:tc:xliff:document:1.1"
в корень таблицы стилей. Я не думаю, что таблица стилей, размещенная в этом вопросе, вообще скомпилируется, учитывая затем использование префиксовmatch="xlf:trans-unit"
без объявления этого. - person Martin Honnen   schedule 19.06.2017xlf
остался от моего раннего теста сxmlns:xlf="urn:oasis:names:tc:xliff:document:1.1"
, который тоже не работал. Я только что исправил это в вопросе. Однако, как я уже упоминал, добавлениеxpath-default-namespace="urn:oasis:names:tc:xliff:document:1.1"
не заставит его работать. - person msoutopico   schedule 19.06.2017