【发布时间】:2011-02-22 18:25:42
【问题描述】:
我在这里发现了一个类似的问题:
How to read attribute of a parent node from a child node in XSLT
但不完全是我需要的。假设在这里使用相同的示例:
<A>
<b attr1="xx">
<c>
Turn this into an Attribute
</c>
</b>
</A>
我希望在 xslt 之后生成的 xml 看起来像:
<A>
<b attr1="xx" cAttr="Turn this into an Attribute">
</b>
</A>
使用我目前的知识,我只能设法摆脱节点或将其名称更改为所需的名称“cAttr”,但我真的不知道如何将整个节点变成父节点的属性, 只知道如何引用父节点的属性字段在这里对我没有多大帮助。
我当前的代码如下所示:
<xsl:template match="c">
<xsl:element name="cAttr">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
提前致谢。
【问题讨论】: