XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="aaa">
<ddd>
<xsl:value-of select="substring-before(.,'[')"/>
<dv name="{substring-before(substring-after(.,'['),']')}"/>
</ddd>
</xsl:template>
</xsl:stylesheet>
或
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="aaa">
<ddd>
<xsl:value-of select="tokenize(.,'\[')[1]"/>
<dv name="{tokenize(tokenize(.,'\[')[2],'\]')[1]}"/>
</ddd>
</xsl:template>
</xsl:stylesheet>
EDIT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="aaa">
<ddd>
<xsl:apply-templates select="node()|@*"/>
</ddd>
</xsl:template>
<xsl:template match="content|component">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="strong">
<dv name="{normalize-space(.)}"/>
</xsl:template>
</xsl:stylesheet>
谢谢你的建议..我编辑了这个问题,你可以修改答案,就像递归地做这件事一样。 – Patan 2012-03-16 12:31:32
@muzimil - 我不确定你递归的意思。您的新输入/输出示例根本不需要字符串操作。你只需要删除'content','component'和'strong'元素并重命名'aaa'元素。 – 2012-03-16 14:16:48
没有我也放弃了内容的一部分..像[a_b_c]等递归我的意思是需要做不止一次(如果更多的东西需要删除)。 – Patan 2012-03-16 14:22:32