【发布时间】:2015-05-29 06:55:51
【问题描述】:
我想将一个 XML 文件转换为 xml,但我还想将一些文本与其他元素进行转换
输入:
<parent> Some parent text
<child1>child text</child1><child2>child text</child2>
more parent text</parent>
期望的输出:
<parent><text>Some parent text</text>
<child1>child text</child><child2>child text</child2>
<text>more parent text</text></parent>
我的 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="text" indent="no"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="parent/text()">
<xsl:element name="node">
<xsl:apply-templates select="text()"/>
</xsl:element>
</xsl:template>
<xsl:template match="child1">
<xsl:element name="child1">
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="child2">
<xsl:element name="child2">
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
无论如何我可以解决这个问题以包含一些带有子节点的子文本吗?
【问题讨论】:
标签: xslt