gpt4 book ai didi

XSLT 创建多个具有相同 ID 和名称的记录

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

我的 XML 输入是:

<vb:Report>
<vb:ID>1111</vb:ID>
<vb:name>tinker bell</vb:name>
<vb:experience >
<vb:title>Consultant1</vb:title>
<vb:company>Coke</vb:company>
<vb:startend>04/01 - 04/30</vb:startend>
</vb:experience>
<vb:experience>
<vb:title> Consultant2</vb:title>
< vb:company>Pepsi</vb:company >
<vb:startend>05/01 - 04/30</vb:startend>
</vb:experience>
</vb:report>

我需要添加“ID”和“姓名”以体验历史并将每条记录写在新行上。

所需输出:
1111 tinker bell Consultant1 Coke 04/01 - 04/30 
1111 tinker bell Consultant2 Pepsi 05/01 - 04/30

谢谢。

最佳答案

确保您的输入 XML 包含命名空间声明,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<XMLRoot xmlns:vb="http://www.vb.org/someNS">
<vb:Report>
<vb:ID>1111</vb:ID>
<vb:name>tinker bell</vb:name>
<vb:experience >
<vb:title>Consultant1</vb:title>
<vb:company>Coke</vb:company>
<vb:startend>04/01 - 04/30</vb:startend>
</vb:experience>
<vb:experience>
<vb:title> Consultant2</vb:title>
<vb:company>Pepsi</vb:company >
<vb:startend>05/01 - 04/30</vb:startend>
</vb:experience>
</vb:Report>
</XMLRoot>

然后进行 XSLT 转换以提供所需的输出:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vb="http://www.vb.org/someNS"
version="1.0">

<xsl:output method="text"/>

<xsl:template match="vb:Report">
<xsl:apply-templates select="vb:experience"/>
</xsl:template>

<xsl:template match="vb:experience">
<xsl:value-of select="concat(
preceding-sibling::vb:ID[1],' ',
preceding-sibling::vb:name[1],' ',
vb:title,' ',
vb:company,' ',
vb:startend)"/>
<xsl:text>&#xa;</xsl:text>
</xsl:template>

</xsl:stylesheet>

你可以在这里试试: https://xsltfiddle.liberty-development.net/bwdwsc/2

关于XSLT 创建多个具有相同 ID 和名称的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59107271/

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