[如果有人可以帮助我创建xslt,以基于重复元素的值(PlayBack--ControlInfo-ControlName1)但不包含空值的方式从XML中删除重复节点,我将不胜感激。
我想从GStep / Step中删除除空值(PlayBack--ControlInfo-ControlName1)以外的所有重复元素>
输入XML
<?xml version="1.0" encoding="utf-8"?> <Document> <Meta> <GpsFile>notepad_may_30_file</GpsFile> <GpsId>36fa4fe8-9691-4a7f-8bc1-9543f6b7d29a</GpsId> <ExePath> <ExePath1>C:\WINDOWS\SYSTEM32\notepad.exe</ExePath1> </ExePath> </Meta> <Process> <GStep DialogName="Untitled - Notepad"> <Step DialogName="Untitled - Notepad"> <Step-ID>3</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>4</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>5</Step-ID> <PlayBack--ControlInfo-ControlName1>Edit</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>6</Step-ID> <PlayBack--ControlInfo-ControlName1>Replace...\tCtrl+H</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>12</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>13</Step-ID> <PlayBack--ControlInfo-ControlName1>Edit</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>14</Step-ID> <PlayBack--ControlInfo-ControlName1>Replace...\tCtrl+H</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>15</Step-ID> <PlayBack--ControlInfo-ControlName1>Cancel</PlayBack--ControlInfo-ControlName1> </Step> </GStep> <GStep DialogName="Replace"> <Step DialogName="Replace"> <Step-ID>8</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Replace"> <Step-ID>9</Step-ID> <PlayBack--ControlInfo-ControlName1>Cancel</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Replace"> <Step-ID>10</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Replace"> <Step-ID>16</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> </GStep> </Process> </Document>
实际上期望得到如下结果。
<?xml version="1.0" encoding="utf-8"?> <Document> <Meta> <GpsFile>notepad_may_30_file</GpsFile> <GpsId>36fa4fe8-9691-4a7f-8bc1-9543f6b7d29a</GpsId> <ExePath> <ExePath1>C:\WINDOWS\SYSTEM32\notepad.exe</ExePath1> </ExePath> </Meta> <Process> <GStep DialogName="Untitled - Notepad"> <Step DialogName="Untitled - Notepad"> <Step-ID>3</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>4</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>5</Step-ID> <PlayBack--ControlInfo-ControlName1>Edit</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>6</Step-ID> <PlayBack--ControlInfo-ControlName1>Replace...\tCtrl+H</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>12</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Untitled - Notepad"> <Step-ID>15</Step-ID> <PlayBack--ControlInfo-ControlName1>Cancel</PlayBack--ControlInfo-ControlName1> </Step> </GStep> <GStep DialogName="Replace"> <Step DialogName="Replace"> <Step-ID>8</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Replace"> <Step-ID>9</Step-ID> <PlayBack--ControlInfo-ControlName1>Cancel</PlayBack--ControlInfo-ControlName1> </Step> <Step DialogName="Replace"> <Step-ID>10</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> <Step DialogName="Replace"> <Step-ID>16</Step-ID> <PlayBack--ControlInfo-ControlName1 /> </Step> </GStep> </Process> </Document>
Xslt代码段。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="ControlNameInfo1" match="Step" use="PlayBack--ControlInfo-ControlName1"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="GStep/Step[not(generate-id() = generate-id(key('ControlNameInfo1', PlayBack-- ControlInfo-ControlName)[1]))]"/> </xsl:stylesheet>
应删除重复的值,但不应删除空的PlayBack--ControlInfo-ControlName1
非常感谢。
如果有人可以帮助我创建xslt,以便基于重复元素的值(PlayBack--ControlInfo-ControlName1)但不包含空值,从XML中删除重复的节点,我将不胜感激。我想...
我发布到您先前的问题的XSLT 3方法的XSLT 1.0转录将是