gpt4 book ai didi

xml - 如何使用 XSLT 1.0 从字符串中提取唯一字符?

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

我在 XSLT 设计中遇到的最艰巨的挑战之一..

如何复制给定字符串中的唯一字符..
测试xml是:

<root>
<string>aaeerstrst11232434</string>
</root>

我期望的输出是:

<string>aerst1234</string>

最佳答案

使用以下 XPath 一行代码:

codepoints-to-string(distinct-values(string-to-codepoints(.)))

使用它的完整转换如下:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="text"/>

<xsl:template match="string">
<xsl:value-of select=
"codepoints-to-string(distinct-values(string-to-codepoints(.)))
"/>
</xsl:template>
</xsl:stylesheet>

当此转换应用于最初提供的 XML 文档时:

<root>
<string>aaeerstrst11232434</string>
</root>

产生了想要的结果:

aerst1234

如果需要 XSLT 1.0 解决方案——请指明,我会提供。

关于xml - 如何使用 XSLT 1.0 从字符串中提取唯一字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2264394/

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