Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将XML文本转换为标记?_Xml_Xslt - Fatal编程技术网

如何将XML文本转换为标记?

如何将XML文本转换为标记?,xml,xslt,Xml,Xslt,有人能告诉我如何使用XSLT将标记中的文本转换成标记名吗 XML: <a> Some topic: </a> <b> Some text on the topic. </b> <Some_topic> Some text on the topic. </Some_topic> 一些话题: 关于这个主题的一些文本。 需要的结果: <a> Some topic: </a>

有人能告诉我如何使用XSLT将标记中的文本转换成标记名吗

XML:

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

一些话题:
关于这个主题的一些文本。
需要的结果:

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

关于这个主题的一些文本。
给定此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>

关于这个主题的一些文本。
让我知道我在你的家庭作业中得到了什么分数-哈哈

<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>

关于这个主题的一些文本。
让我知道我在你的家庭作业中得到了什么分数-哈哈