XSLT を使用して次の XML を変換できますか?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<p>The chemical formula for water is H<sub>2</sub>O. The rest of this paragraph is not relevant.</p>
<p>Another paragraph without subscripts.</p>
</Root>
これに:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<p><text>The chemical formula for water is H</text><sub>2</sub><text>O. The rest of this paragraph is not relevant.</text></p>
<p>Another paragraph without subscripts.</p>
</Root>
つまり、サブ要素を含む ap 要素のさまざまな部分をテキスト要素にラップしますか?
これまでのところ、これは私の XSLT です。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="Root|p">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="p[child::*[name()='sub']]">
<xsl:copy>
<xsl:element name="text">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:copy>
</xsl:template>
<xsl:template match="sub">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
しかし、それは段落全体を要素にラップし、それを2<text>
で分割しません。どうすればやりたいことができるようになりますか?
興味がある場合は、少し背景情報: XML を Adobe InDesign にインポートしたいのですが、文字スタイルサブをサブ要素にのみ適用すると、段落の後半 (O で始まる) が残ります。添字。<text>
フォーマットを正しくするには、他のビットをラップする必要があります。