すべてのテキスト ノードを検索し、新しいノード シーケンスを作成する必要があります (入力/出力 XML を参照)。インライン ノード (テキスト ノードの先行兄弟または後続兄弟) がある場合は、それらのタグの名前を <x id= に変更します。 "XX" local-name='tagName'>text here </x> ここで、「local-name」の値はそのノードの名前である必要があります。これらのインライン ノードは、特定のリストではなく、何でもかまいません。どんなポインタ/解決策も大いに役立ちます。ありがとう。
XSLT バージョン 2.0 XSLT プロセッサ - Saxon EE/HE 9.XXX
<?xml version="1.0" encoding="utf-8"?>
<concept id="001" xml:lang="en-us">
<title id="002">Notice</title>
<shortdesc id="003">This information U.S.A.</shortdesc>
<conbody id="004">
<p id="005">This product blah blah <companyname id="006">blah bla</companyname> No other
warranty expressed or implied. </p>
<p id="007">This supersedes all previous notices.</p>
<section id="008">
<title id="009">COPYRIGHT LICENSE:</title>
<p id="010">This information contains <b id="011">in source language</b> , blah blah</p>
</section>
</conbody>
</concept>
期待される出力:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<trans-unit id="002">
<source>Notice</source>
<target>Notice</target>
</trans-unit>
<trans-unit id="003">
<source>This information U.S.A.</source>
<target>This information U.S.A.</target>
</trans-unit>
<trans-unit id="005">
<source>This product blah blah <x id="006" local-name="companyname">blah bla</x> No other
warranty expressed or implied. </source>
<target>This product blah blah <x id="006" local-name="companyname">blah bla</x> No other
warranty expressed or implied.</target>
</trans-unit>
<trans-unit id="007">
<source>This supersedes all previous notices.</source>
<target>This supersedes all previous notices.</target>
</trans-unit>
<trans-unit id="009">
<source>COPYRIGHT LICENSE:</source>
<target>COPYRIGHT LICENSE:</target>
</trans-unit>
<trans-unit id="010">
<source>This information contains <x id="011" local-name="b">in source language</x> , blah
blah</source>
<target>This information contains <x id="011" local-name="b">in source language</x> , blah
blah</target>
</trans-unit>
</root>
私はこのようなことを試みています:
<xsl:template match="/">
<root>
<xsl:for-each select="//text()">
<xsl:if test=".!='' or .!=' '">
<xsl:choose>
<xsl:when test="not(following-sibling::node()) or not(preceding-sibling::node())">
<trans-unit>
<xsl:attribute name="id">
<xsl:value-of select="../@id"/>
</xsl:attribute>
<source>
<xsl:value-of select="."/>
</source>
<target>
<xsl:value-of select="."/>
</target>
</trans-unit>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</root>