2017-01-09 37 views
0

任何人都可以告訴我如何使用XSLT將標籤中的文本放入標籤名稱中?如何將XML文本轉換爲標籤?

XML:

<a> 
    Some topic: 
</a> 
<b> 
    Some text on the topic. 
</b> 

所需結果:

<Some_topic> 
    Some text on the topic. 
</Some_topic> 

回答

3

鑑於這種XML

<xml> 
<a> 
    Some topic: 
</a> 
<b> 
    Some text on the topic. 
</b> 
</xml> 

使用此XSL

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <xsl:variable name='element' select="translate(normalize-space(/xml/a), ' :', '_')"/> 
    <xsl:element name='{$element}'> 
     <xsl:value-of select='/xml/b'/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 

爲了生產

<?xml version="1.0" encoding="UTF-16"?> 
<Some_topic> 
    Some text on the topic. 
</Some_topic> 

讓我知道我的品位我得到你的家庭作業-ha公頃