gpt4 book ai didi

xml - 将元素值连接到一行

转载 作者:行者123 更新时间:2023-12-04 04:33:16 24 4
gpt4 key购买 nike

如何将三个元素名称、年龄和国家/地区连接到一行?

<?xml version="1.0" encoding="utf-8"?>
<Person>
<Student>
<Name>James</Name>
<Age>21</Age>
<Country>Australia </Country>
</Student>
</Person>

所以我可以将元素值设为一行。
<info> ....... <info>

最佳答案

简单就这样做;

XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Student">
<xsl:element name = "Info">
<xsl:value-of select="concat(Name,' is ',Age,' born in ',Country)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

刚刚添加了额外的文本,您可以将其删除或使用 ' '(空白),这样您就可以获得空格。

输出:
<?xml version="1.0" encoding="UTF-8"?>
<Info>James is 21 born in Australia </Info>

有空格;
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Student">
<xsl:element name = "Info">
<xsl:value-of select="concat(Name,' ',Age,' ',Country)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

输出:
<?xml version="1.0" encoding="UTF-8"?>
<Info>James 21 Australia </Info>

关于xml - 将元素值连接到一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20208014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com