gpt4 book ai didi

xml - XSLT 1.0 : Efficiently Compare Two Nodesets for a Match

转载 作者:数据小太阳 更新时间:2023-10-29 03:01:35 24 4
gpt4 key购买 nike

我有一个像这样的颜色元素序列:

<Colors>
<Color Name ="AliceBlue" Hex="#F0F8FF"/>
<Color Name ="AntiqueWhite" Hex="#FAEBD7"/>
<!-- more values... -->
</Colors>

还有一个单词序列:

<Words>
<Element>1px</Element>
<Element>Blue</Element>
<Element>Solid</Element>
</Words>

找到 Colors/Color/@name 属性与 Words/Element/text() 中的节点完全匹配并检索该节点的有效方法是什么?姓名?

最佳答案

正如@michael.hor257k 所建议的,您可以为此使用 key ;假设这个示例文档:

<root>
<Colors>
<Color Name ="AliceBlue" Hex="#F0F8FF"/>
<Color Name ="AntiqueWhite" Hex="#FAEBD7"/>
<Color Name="AnotherColor" Hex="123" />
<!-- more values... -->
</Colors>
<Words>
<Element>1px</Element>
<Element>Blue</Element>
<Element>AntiqueWhite</Element>
<Element>AliceBlue</Element>
</Words>
</root>

这个 XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:key name="colors" match="/root/Colors/Color" use="@Name" />
<xsl:template match="/root/Words/Element[key('colors', .)]">
<xsl:value-of select="." />
</xsl:template>

<xsl:template match="text()" />
</xsl:transform>

将输出在 ElementColor 节点中匹配的颜色名称。这是 XSLTransform .

关于xml - XSLT 1.0 : Efficiently Compare Two Nodesets for a Match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32463684/

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