首页 \ 问答 \ XSLT2.0删除节点中的重复值(XSLT2.0 Remove duplicate values in node)

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
更新时间:2022-07-03 17:07

最满意答案

这是一篇非常好的文章:

它从Web.Config中获取灵感......毕竟它只是一个XML文件。

Conn.test.Config

Conn.test.Config

App.test.Config

App.live.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.

Conn.test.Config

Conn.test.Config

App.test.Config

App.live.Config

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.

相关问答

更多
  • 关于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 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.
  • 询问您的虚拟主机是否可以通过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 ...
  • 阅读以下文章: “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揭秘 它从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"); 如果你只是想替换一 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)