1
我有這樣的XML文檔:如何繼承當前XSLT上下文中的元素名稱?
<?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? –