我需要你帮助修复我的xslt。
我的要求是根据其死亡(孙子)值删除特定的子节点。
在下面的示例中,我需要编写一个xslt,它给出了包含xml的内容 其死亡“SID”值不等于“1113181”
<CDM CDMVersion="1.3" FType="Transactional" FOID="85b40b86-e6f1-4813-a5f4-0b98c90bd72d" CreationDateTime="2016-08-19T19:04:25" xmlns="http://www.example.com/ns/CDM/v1.3" xmlns:xyz="http://www.example.com/ns/CDM/MData">
<TestData EduOID="LX4211-204" MDataVersionOID="34" xyz:AuditSubCategoryName="Verify">
<SubData SubKey="5117f771-790f-4cde-b261-1a2db0dcd04b" xyz:SubKeyType="SubUUID" xyz:SubName="204-0114-002">
<SRef LocOID="LX4211204_0114"/>
<SubEventData EduEventOID="EOT" EduEventRepeatKey="EOT[1]" xyz:InstanceId="76194">
<FmData FmOID="VS2" FmRepeatKey="1" xyz:DataPageId="388465">
<IGroupData IGroupOID="VS2" xyz:RecordId="1044557">
<IData ItemOID="VS2.VSORRES4_2" TransactionType="Upsert" xyz:Verify="Yes">
<Record>
<TesterRef TesterOID="bballardamad1"/>
<LocRef LocOID="LX4211204_0114"/>
<DateTimeStamp>2016-08-16T17:07:15</DateTimeStamp>
<ReasonForChange/>
<SID>1113181</SID>
</Record>
</IData>
</IGroupData>
</FmData>
</SubEventData>
</SubData>
</TestData>
<TestData EduOID="LX4211-204" MDataVersionOID="34" xyz:AuditSubCategoryName="QueryClose">
<SubData SubKey="5117f771-790f-4cde-b261-1a2db0dcd04b" xyz:SubKeyType="SubUUID" xyz:SubName="204-0114-002">
<SRef LocOID="LX4211204_0114"/>
<SubEventData EduEventOID="EOT" EduEventRepeatKey="EOT[1]" xyz:InstanceId="76194">
<FmData FmOID="VS2" FmRepeatKey="1" xyz:DataPageId="388465">
<IGroupData IGroupOID="VS2" xyz:RecordId="1044557">
<IData ItemOID="VS2.VSORRES4_2" TransactionType="Upsert">
<Record>
<TesterRef TesterOID="bballardamad1"/>
<LocRef LocOID="LX4211204_0114"/>
<DateTimeStamp>2016-08-16T17:07:15</DateTimeStamp>
<ReasonForChange/>
<SID>1113182</SID>
</Record>
<xyz:Query QueryRepeatKey="552326" Status="Closed" Recipient="Site from CRA"/>
</IData>
</IGroupData>
</FmData>
</SubEventData>
</SubData>
</TestData>
<TestData EduOID="LX4211-204" MDataVersionOID="34" xyz:AuditSubCategoryName="Verify">
<SubData SubKey="5117f771-790f-4cde-b261-1a2db0dcd04b" xyz:SubKeyType="SubUUID" xyz:SubName="204-0114-002">
<SRef LocOID="LX4211204_0114"/>
<SubEventData EduEventOID="WK1_POST" EduEventRepeatKey="WK1_POST[1]" xyz:InstanceId="119171">
<FmData FmOID="VS2" FmRepeatKey="1" xyz:DataPageId="670872">
<IGroupData IGroupOID="VS2" xyz:RecordId="1934354">
<IData ItemOID="VS2.VSORRES12" TransactionType="Upsert" xyz:Verify="Yes">
<Record>
<TesterRef TesterOID="bballardamad1"/>
<LocRef LocOID="LX4211204_0114"/>
<DateTimeStamp>2016-08-16T17:09:10</DateTimeStamp>
<ReasonForChange/>
<SID>1114610</SID>
</Record>
</IData>
</IGroupData>
</FmData>
</SubEventData>
</SubData>
</TestData>
</CDM>
=============================================== =================================
我的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:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!--<xsl:template match="//SID[text()!=1113181]"/>-->
<xsl:template match="/CDM/TestData/SubData/SubEventData/FmData/IGroupData/IData/Record/SID[text()!=68943181]"/>
</xsl:stylesheet>
预期产出:
#<CDM CDMVersion="1.3" FType="Transactional" FOID="85b40b86-e6f1-4813-a5f4-0b98c90bd72d" CreationDateTime="2016-08-19T19:04:25" xmlns="http://www.example.com/ns/CDM/v1.3" xmlns:xyz="http://www.example.com/ns/CDM/MData">
<TestData EduOID="LX4211-204" MDataVersionOID="34" xyz:AuditSubCategoryName="QueryClose">
<SubData SubKey="5117f771-790f-4cde-b261-1a2db0dcd04b" xyz:SubKeyType="SubUUID" xyz:SubName="204-0114-002">
<SRef LocOID="LX4211204_0114"/>
<SubEventData EduEventOID="EOT" EduEventRepeatKey="EOT[1]" xyz:InstanceId="76194">
<FmData FmOID="VS2" FmRepeatKey="1" xyz:DataPageId="388465">
<IGroupData IGroupOID="VS2" xyz:RecordId="1044557">
<IData ItemOID="VS2.VSORRES4_2" TransactionType="Upsert">
<Record>
<TesterRef TesterOID="bballardamad1"/>
<LocRef LocOID="LX4211204_0114"/>
<DateTimeStamp>2016-08-16T17:07:15</DateTimeStamp>
<ReasonForChange/>
<SID>1113182</SID>
</Record>
<xyz:Query QueryRepeatKey="552326" Status="Closed" Recipient="Site from CRA"/>
</IData>
</IGroupData>
</FmData>
</SubEventData>
</SubData>
</TestData>
<TestData EduOID="LX4211-204" MDataVersionOID="34" xyz:AuditSubCategoryName="Verify">
<SubData SubKey="5117f771-790f-4cde-b261-1a2db0dcd04b" xyz:SubKeyType="SubUUID" xyz:SubName="204-0114-002">
<SRef LocOID="LX4211204_0114"/>
<SubEventData EduEventOID="WK1_POST" EduEventRepeatKey="WK1_POST[1]" xyz:InstanceId="119171">
<FmData FmOID="VS2" FmRepeatKey="1" xyz:DataPageId="670872">
<IGroupData IGroupOID="VS2" xyz:RecordId="1934354">
<IData ItemOID="VS2.VSORRES12" TransactionType="Upsert" xyz:Verify="Yes">
<Record>
<TesterRef TesterOID="bballardamad1"/>
<LocRef LocOID="LX4211204_0114"/>
<DateTimeStamp>2016-08-16T17:09:10</DateTimeStamp>
<ReasonForChange/>
<SID>1114610</SID>
</Record>
</IData>
</IGroupData>
</FmData>
</SubEventData>
</SubData>
</TestData>
</CDM>
#
答案 0 :(得分:2)
您的尝试不起作用有四个原因:
TestData
,请将其与TestData
匹配 - 而不是其后代; <TestData>
,其后代SID
值不等于1113181
,那么请移除模板匹配TestData
,其后代SID
值 等于1113181
; 68943181
不是1113181
。尝试:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cdm="http://www.example.com/ns/CDM/v1.3">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="cdm:TestData[cdm:SubData/cdm:SubEventData/cdm:FmData/cdm:IGroupData/cdm:IData/cdm:Record/cdm:SID=1113181]"/>
</xsl:stylesheet>