【发布时间】:2016-07-01 06:59:39
【问题描述】:
我有一个这样的 XML 文档:
<?xml version="1.0" encoding="utf-8" ?>
<article properName="Article">
<h1>
This <strong>is a header</strong>
</h1>
<p>This is a <strong>paragraph</strong</p>
</article>
我需要把它转换成这个:
<?xml version="1.0" encoding="utf-8" ?>
<Article>
<Article-bigheader>
This <Article-bigheader-bold>is a header</Article-bigheader-bold>
</Article-bigheader>
<Article-paragraph>This is a <Article-paragraph-bold>paragraph</Article-paragraph-bold></Article-paragraph>
</Article>
原始文档中的元素将具有不同的名称并以不同的方式嵌套,因此我需要动态地执行此操作,而不是为每个可能的组合创建一个 xsl 模板。我遇到问题的具体部分是文本装饰,如何创建一个元素,其名称为包含 XSLT 元素的名称和附加的“-bold”后缀? 这是我到目前为止所得到的:
<xsl:template match="/article">
<xsl:element name="{@properName}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="h1">
<xsl:element name="{concat(/article/@properName, '-', 'bigheader')}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
【问题讨论】:
-
您使用的是 XSLT 1.0 还是 2.0?