【问题标题】:XSL flatten with inheritXSL 扁平化继承
【发布时间】:2019-08-14 07:53:10
【问题描述】:

我想展平一个 XML 文档,这样每个元素都会复制其父元素的属性并将 <span/> 转换为 <text/>
输入:

<el value="
    <span bold="true">
        one
        <span italics="true">
            two
            <span superscript="true">
                three
            </span>
        </span>
    </span>
    <span subscript="true">
        four
    </span>
"/>

输出:

<text bold="true">one</text>
<text bold="true" italics="true">two</text>
<text bold="true" italics="true" superscript="true">three</text>
<text subscript="true">four</text>

我尝试过将copy-of.. 一起使用,但这显然只会从输入向上复制一层。我认为我需要一个变量,但我不确定如何对其进行操作 - 我似乎无法做到 &lt;xsl:value-of select="$text-element"&gt;&lt;!--call template--&gt;&lt;/xsl:value-of&gt;。这是属性内的字符串这一事实也无济于事......

【问题讨论】:

标签: xslt


【解决方案1】:

一旦你使 XML 格式正确,这样的事情可能会有所帮助:

<xsl:template match="text()">
  <text>
    <xsl:copy-of select="ancestor::*/@*"/>
    <xsl:value-of select="normalize-space()"/>
  </text>
</xsl:template>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2016-04-02
    • 2018-05-24
    相关资源
    最近更新 更多