XSLT2.0删除节点中的重复值(XSLT2.0 Remove duplicate values in node)
我一直在试图弄清楚如何使用XSLT从XML文档中删除具有重复值的元素。
例如:输入:
<main> <h1> <node1>duplicate</node1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> <node1>duplicate</node1> </h1> </main>
预期产出:
<main> <h1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> </h1> </main>
我相信这一定不会太复杂,但我无法理解迄今为止见过的任何方法。 谢谢!
感谢下面的Michael! 例如,如果上面的例子有更多的节点(永远不会重复),我还有一个问题
<main> <h1> <node1>duplicate</node1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> <node1>duplicate</node1> <node2> Data </node2> </h1> </main>
我将如何通过XSLT代码提供这些数据? 以下解决方案删除了我发现的任何其他数据,尽管我理解了要复制所有的身份转换,以及仅修改匹配模板的匹配。
I have been trying to figure out how to remove elements with duplicate values from an XML document using XSLT.
For example: Input:
<main> <h1> <node1>duplicate</node1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> <node1>duplicate</node1> </h1> </main>
expected output:
<main> <h1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> </h1> </main>
I'm sure this must not be too complicated but I am failing to understand any methods I have seen so far. Thanks!
Thanks to Michael below! I have a further question, if the above example had more nodes (which would never be duplicate), for example
<main> <h1> <node1>duplicate</node1> <node1>duplicate</node1> <node1>New data</node1> <node1>New data 2</node1> <node1>duplicate</node1> <node2> Data </node2> </h1> </main>
How would I bring this data through in the XSLT code? The below solution removes any additional data I have found despite my understanding of the identity transform to copy all, and the match to modify only matching templates.
原文:https://stackoverflow.com/questions/34901852
最满意答案
这是一篇非常好的文章:
它从Web.Config中获取灵感......毕竟它只是一个XML文件。
关于将AppSettings放在单独的文件中的另一个链接。 我一直这样做。 我将有几个文件,我的测试环境不同,有类似的东西:
Conn.test.Config
Conn.test.Config
App.test.Config
App.live.Config
并且...一个很好的方式来找出人们发现有用的东西是标记为美味的Web.Config的项目
我也很高兴向人们展示IIS中ASP.Net选项卡下的花哨“网站配置”只是解析一个XML文件,并没有什么特别之处。
This is a really good article:
It takes the magic out of the Web.Config... which after all is just an XML file.
Another link about putting AppSettings in a separate File. I do this ALL THE TIME. I'll have several files where my test environment are different and have something like:
Conn.test.Config
Conn.test.Config
App.test.Config
App.live.Config
Here's MSDN docs which outline the additions for .Net 3.5.
AND... one GREAT way of finding out what people have found to be useful is the items tagged Web.Config in delicious
I also love showing people that the fancy "website configuration" under the ASP.Net Tab in IIS is just parsing an XML file and there's nothing fancy about it.
相关问答
更多-
何时读取web.config?(When is web.config read?)[2022-06-08]
关于asp.net configration文件如何工作的最全面的描述是我在MSDN上的这个: ASP.NET配置文件层次结构和继承 它是为.NET 3.5框架编写的,因此信息应该是您可能找到的最新信息。 它详细描述了如何读取各种配置文件并将其合并到应用程序的运行时设置中。 The most comprehensive description of how asp.net configration files work that I know of is this one at MSDN: ASP.NET ... -
是的,web.config的问题在于它不是租户意识的。 在Orchard中处理设置的推荐方法是在站点内容类型中添加部件。 整个代码中有很多例子。 这应该给你一些更多的信息: http : //docs.orchardproject.net/Documentation/Adding-custom-settings Yes, the problem with web.config is that it is not tenant-aware. The recommended way of treating se ...
-
对于初学者,您可以快速更新web.config中的API密钥。 您将不得不重新编译该类并重新部署该类。 您也可以从asp.net 2.0开始加密web.config部分的部分 http://weblogs.asp.net/scottgu/archive/2006/01/09/434893.aspx 如果你可以将它保存在machine.config中,那将确保它只能在该机器上运行,而不会在其他地方运行。 Web.Configs需要放置在每个环境中,尽管可以保持每台机器的web.config不同,但随着时间的推 ...
-
我可以从Azure Web角色入口点访问web.config吗?(Can I access web.config from my Azure web role entry point?)[2021-01-08]
原因是微软自Azure SDK 1.3以来推出了完整的IIS功能。 这样做的副作用是RoleEntryPoint与Web应用程序的其余部分隔离开来。 以下来自Microsofts 博客文章的摘录描述了您所看到的内容。 ...在完整的IIS中,RoleEntryPoint在WaIISHost.exe下运行 ,而网站在正常的IIS w3wp.exe进程下运行。 ...所以它希望它的配置位于名为WaIISHost.exe.config的文件中。 因此,如果您在Web项目中使用此名称创建一个文件,并将“复制到输出目 ... -
我总是(直到强迫相反的东西)按字母顺序排序所有内容(部分,节点,子节点),除了部分的声明,必须先行。 I always (until something forces the opposite) sort everything alphabetically (sections, nodes, subnodes), except sections' declaration, which have to going first.
-
web.config urlmapping(web.config urlmapping)[2024-01-28]
询问您的虚拟主机是否可以通过ASP.Net配置您的虚拟目录以提供所有请求。 许多主机(包括我的)都愿意这样做。 (提到ASP.Net MVC,这需要这个) Ask your web host if they can configure your virtual directory to serve all requests through ASP.Net. Many hosts (mine included) are willing to do this. (Mention ASP.Net MVC, whi ... -
有人能指出我从C#到Java的良好迁移指南吗?(Can someone point me to a good migration guide from C# to Java? [closed])[2023-05-14]
阅读以下文章: “Microsoft的C#编程Lanauge与Sun Microsystems的Java编程Langauge的比较” “Java与C#:代码比较代码” (语言细微差别指南) “C#vs Java第3部分:框架(网络,反射,安全,文本)” “C#vs Java第3部分:框架(IO,DB,并发,集合)” 也可以看看: “比较C#和Java” “比较Java和C#泛型” “从.NET开发人员的角度学习Java” “Java开发人员的C#编程语言” 相关的SO问题: “将项目从C#迁移到Java” ... -
MSDN - ASP.NET配置概述 MSDN - ASP.NET配置文件层次结构和继承 MSDN - ASP.NET配置设置 MSDN - ASP.NET Configuration Overview MSDN - ASP.NET Configuration File Hierarchy and Inheritance MSDN - ASP.NET Configuration Settings
-
有人能指出一个非常容易理解的web.config指南吗?(Can someone point me to a really easy to understand guide to web.config?)[2024-02-19]
这是一篇非常好的文章: Web.Config揭秘 它从Web.Config中获取灵感......毕竟它只是一个XML文件。 使用应用程序设置和连接字符串的最佳实践 关于将AppSettings放在单独的文件中的另一个链接。 我一直这样做。 我将有几个文件,我的测试环境不同,有类似的东西: Conn.test.Config Conn.test.Config App.test.Config App.live.Config 这是MSDN文档,概述了.Net 3.5的附加内容 。 并且...一个很好的方式来找出人们 ... -
我想下面 $cfg = [xml](gc web.config) # Replace all references of the IP in all connection string $cfg.configuration.connectionStrings.add|%{ $_.connectionString = $_.connectionString -replace "192.168.1.100", "1.0.0.1"; } $cfg.Save("Web.config"); 如果你只是想替换一 ...