我有源html ......这样:
<td id="All_Label_Subcategories">
<source>
All Label Subcategories
</source>
<target>
target empty
</target>
</td>
<td id='node_without_child_nodes'>
some text
</td>
预期目标xml:
<trans-unit id="td-1">
<source>All Label Subcategories</source>
<target>target empty</target>
</trans-unit>
<trans-unit id="td-2">
<source>some text</source>
<target>some text</target>
</trans-unit>
我正在使用来自xliffRoundTrip Tool的xslt,我不确定我是否应该通过这里的整个xlst,但它开源了。负责此转换并需要修改的部分xslt是:
<xsl:choose>
<xsl:when test="not(text())">
<group xmlns="urn:oasis:names:tc:xliff:document:1.2" id="{concat(generate-id(),'axmark',local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<xsl:apply-templates />
</group>
</xsl:when>
<xsl:otherwise>
<group xmlns="urn:oasis:names:tc:xliff:document:1.2" id="{concat(generate-id(),'axmark',local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<trans-unit id="{concat(local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<source>
<xsl:apply-templates />
</source>
<target>
<xsl:apply-templates />
</target>
</trans-unit>
</group>
</xsl:otherwise>
</xsl:choose>
我的目的是传递目标语言的自定义数据,因为在很多情况下我们需要修改目标语言并传递目标字符串进行修订。
编辑 我修改了xslt但它复制了两次e。克
<xsl:choose>
<xsl:when test="not(text()) and not(*[source and target]) ">
<xsl:choose>
<xsl:when test="*[source and target]">
<trans-unit id="{concat(local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<source match="source">
<xsl:apply-templates />
</source>
<target match="target">
<xsl:apply-templates />
</target>
</trans-unit>
</xsl:when>
<xsl:otherwise>
<group xmlns="urn:oasis:names:tc:xliff:document:1.2" id="{concat(generate-id(),'axmark',local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<xsl:apply-templates />
</group>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<group xmlns="urn:oasis:names:tc:xliff:document:1.2" id="{concat(generate-id(),'axmark',local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<trans-unit id="{concat(local-name(),'-',(count(preceding::*)+count(ancestor::*)))}">
<source>
<xsl:apply-templates />
</source>
<target>
<xsl:apply-templates />
</target>
</trans-unit>
</group>
</xsl:otherwise>
</xsl:choose>
答案 0 :(得分:0)
<xsl:apply-templates select="//*[source and target]"/>
…
<xsl:template match="td[source and target]">
<trans-unit id="td-{position()}">
<xsl:copy-of select="*"/>
</trans-unit>
<xsl:template>
可能会工作。首先尝试独立,没有时髦的开源工具。
答案 1 :(得分:0)
给出像
这样的源文件<?xml version="1.0" encoding="UTF-8"?>
<root>
<td id="All_Label_Subcategories">
<source>All Label Subcategories</source>
<target>target empty</target>
</td>
<td id="node_without_child_nodes">some text</td>
</root>
和这个样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/root">
<xsl:for-each select="td">
<xsl:choose>
<xsl:when test="not(text())">
<trans-unit id="{concat(local-name(),'-',(count(preceding-sibling::td) + 1))}">
<xsl:copy-of select="*"/>
</trans-unit>
</xsl:when>
<xsl:otherwise>
<trans-unit id="{concat(local-name(),'-',(count(preceding-sibling::td) + 1))}">
<source>
<xsl:apply-templates />
</source>
<target>
<xsl:apply-templates />
</target>
</trans-unit>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<强>输出强>
<trans-unit id="td-1">
<source>All Label Subcategories</source>
<target>target empty</target>
</trans-unit>
<trans-unit id="td-2">
<source>some text</source>
<target>some text</target>
</trans-unit>