如何使用 xsl 将文本传输到属性?
How to transfer text to the attribute with xsl?
我在获得正确的 xsl 转换结果时遇到了问题。当我从 Indesign 导出我的 xml 文档时,没有任何转换,生成了以下代码:
<text>aerher<b>hea</b>rh er<i>haeh</i> rehe eageag</text>
它应该看起来像这样:
<text value="aerher[b]hea[/b]rh er[i]haeh[/i] rehe eageag" />
另请注意,<b>
如何转变为 [b]
。现在我最大的问题是,我什至没有选择所有文本。通过以下转换,我的结果如下所示:
<xsl:template match="text">
<text value="{text()}"/>
</xsl:template>
<text value="aerher"/>
如何获得包含我的标签的完整文本?我会自己找出如何将 <b>
转换为 [b]
。我只是想不通,为什么它没有选择我的所有文本?
<b>
不是 <text>
元素包含的文本节点的一部分 - 它是 markup。如果您想将标记转换为文本(即伪标记),请尝试以下方法:
<xsl:template match="text">
<xsl:copy>
<xsl:attribute name="value">
<xsl:apply-templates/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:text>[b]</xsl:text>
<xsl:apply-templates/>
<xsl:text>[/b]</xsl:text>
</xsl:template>
<xsl:template match="i">
<xsl:text>[i]</xsl:text>
<xsl:apply-templates/>
<xsl:text>[/i]</xsl:text>
</xsl:template>
我在获得正确的 xsl 转换结果时遇到了问题。当我从 Indesign 导出我的 xml 文档时,没有任何转换,生成了以下代码:
<text>aerher<b>hea</b>rh er<i>haeh</i> rehe eageag</text>
它应该看起来像这样:
<text value="aerher[b]hea[/b]rh er[i]haeh[/i] rehe eageag" />
另请注意,<b>
如何转变为 [b]
。现在我最大的问题是,我什至没有选择所有文本。通过以下转换,我的结果如下所示:
<xsl:template match="text">
<text value="{text()}"/>
</xsl:template>
<text value="aerher"/>
如何获得包含我的标签的完整文本?我会自己找出如何将 <b>
转换为 [b]
。我只是想不通,为什么它没有选择我的所有文本?
<b>
不是 <text>
元素包含的文本节点的一部分 - 它是 markup。如果您想将标记转换为文本(即伪标记),请尝试以下方法:
<xsl:template match="text">
<xsl:copy>
<xsl:attribute name="value">
<xsl:apply-templates/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<xsl:template match="b">
<xsl:text>[b]</xsl:text>
<xsl:apply-templates/>
<xsl:text>[/b]</xsl:text>
</xsl:template>
<xsl:template match="i">
<xsl:text>[i]</xsl:text>
<xsl:apply-templates/>
<xsl:text>[/i]</xsl:text>
</xsl:template>