我需要在重复节点的最后一个子节点之后添加一个节点 我有一个带有节点参数的XML,它是成熟的 我需要在参数
的最后一个节点之后添加一个节点这是我的档案:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SyncPulseTask releaseID="10.1.3" xmlns="http://schema.infor.com/InforOAGIS/2">
<ApplicationArea>
<Sender>
<LogicalID>infor.engine.pulse</LogicalID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2014-09-29T15:47:05.080Z</CreationDateTime>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor</TenantID>
<ActionCriteria>
<ActionExpression actionCode="Add"/>
</ActionCriteria>
</Sync>
<PulseTask>
<DocumentID>
<ID variationID="1">756</ID>
</DocumentID>
<CreationDateTime>2014-09-29T15:47:04Z</CreationDateTime>
<LastModificationDateTime>2014-09-29T15:47:05Z</LastModificationDateTime>
<Status>
<Code>NEW</Code>
</Status>
<EscalationLevel>0</EscalationLevel>
<Priority>MEDIUM</Priority>
<Description>Generate Pulse BOD</Description>
<Source>
<Type>WORKFLOW</Type>
<Name>LN_DA_ProjectContractLine</Name>
<Version>46.0</Version>
</Source>
<Parameter sequence="1">
<Name>Contract</Name>
<Value>CON000089</Value>
<DataType>STRING</DataType>
<Label>Contract</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="2">
<Name>ContractAmount</Name>
<Value>1.0</Value>
<DataType>DECIMAL</DataType>
<Label>Contract Amount</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="3">
<Name>ContractCurrency</Name>
<Value>GBP</Value>
<DataType>STRING</DataType>
<Label>Contract Currency</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="4">
<Name>ContractLine</Name>
<Value>0030</Value>
<DataType>STRING</DataType>
<Label>Contract Line</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="5">
<Name>ContractManager</Name>
<Value>RDKORTE</Value>
<DataType>STRING</DataType>
<Label>Contract Manager</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="6">
<Name>ContractManagerName</Name>
<Value>Ron de Korte</Value>
<DataType>STRING</DataType>
<Label>Contract Manager Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="7">
<Name>ExternalSalesRepName</Name>
<Value>Jan Slag</Value>
<DataType>STRING</DataType>
<Label>External Sales Rep Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="8">
<Name>ExternalSalesRepresentative</Name>
<Value>JSLAG</Value>
<DataType>STRING</DataType>
<Label>External Sales Representative</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="9">
<Name>InternalSalesRepName</Name>
<Value>James Rea</Value>
<DataType>STRING</DataType>
<Label>Internal Sales Rep Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="10">
<Name>InternalSalesRepresentative</Name>
<Value>JREA</Value>
<DataType>STRING</DataType>
<Label>Internal Sales Representative</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="11">
<Name>LogicalId</Name>
<Value>lid://infor.ln.infor_ln_10_3_1_company_512</Value>
<DataType>STRING</DataType>
<Label>Logical Id</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="12">
<Name>SalesOffice</Name>
<Value>SBASUK</Value>
<DataType>STRING</DataType>
<Label>Sales Office</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="13">
<Name>SoldToBPName</Name>
<Value>BAES CS&S</Value>
<DataType>STRING</DataType>
<Label>Sold To BPName</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="14">
<Name>SoldToBusinessPartner</Name>
<Value>K0999</Value>
<DataType>STRING</DataType>
<Label>Sold To Business Partner</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="15">
<Name>SoldToContact</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Sold To Contact</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="16">
<Name>SoldToContactName</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Sold To Contact Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="17">
<Name>Status</Name>
<Value>20</Value>
<DataType>INTEGER</DataType>
<Label>Status</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="18">
<Name>StatusBeforeOnHold</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Status Before On Hold</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="19">
<Name>StatusOld</Name>
<Value>0</Value>
<DataType>INTEGER</DataType>
<Label>Status Old</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="20">
<Name>StatusOldName</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Status Old Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="21">
<Name>StatusPreviousOld</Name>
<Value>0</Value>
<DataType>INTEGER</DataType>
<Label>Status Previous Old</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="22">
<Name>SubmitUser</Name>
<Value>infor20</Value>
<DataType>STRING</DataType>
<Label>Submit User</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="23">
<Name>TaskUser</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Task User</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="24">
<Name>WF_Reason</Name>
<Value/>
<DataType>STRING</DataType>
<Label>WF Reason</Label>
<ReadOnlyIndicator>false</ReadOnlyIndicator>
</Parameter>
<DistributionPerson>
<ID>768</ID>
<PersonReference>
<IDs>
<ID>mike.tollan@sharelnk30.net</ID>
</IDs>
<Name>Mike Tollan</Name>
<SystemUserIndicator>true</SystemUserIndicator>
</PersonReference>
</DistributionPerson>
</PulseTask>
</DataArea>
</SyncPulseTask>`
这就是我想要的
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SyncPulseTask releaseID="10.1.3" xmlns="http://schema.infor.com/InforOAGIS/2">
<ApplicationArea>
<Sender>
<LogicalID>infor.engine.pulse</LogicalID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2014-09-29T15:47:05.080Z</CreationDateTime>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor</TenantID>
<ActionCriteria>
<ActionExpression actionCode="Add"/>
</ActionCriteria>
</Sync>
<PulseTask>
<DocumentID>
<ID variationID="1">756</ID>
</DocumentID>
<CreationDateTime>2014-09-29T15:47:04Z</CreationDateTime>
<LastModificationDateTime>2014-09-29T15:47:05Z</LastModificationDateTime>
<Status>
<Code>NEW</Code>
</Status>
<EscalationLevel>0</EscalationLevel>
<Priority>MEDIUM</Priority>
<Description>Generate Pulse BOD</Description>
<Source>
<Type>WORKFLOW</Type>
<Name>LN_DA_ProjectContractLine</Name>
<Version>46.0</Version>
</Source>
<Parameter sequence="1">
<Name>Contract</Name>
<Value>CON000089</Value>
<DataType>STRING</DataType>
<Label>Contract</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="2">
<Name>ContractAmount</Name>
<Value>1.0</Value>
<DataType>DECIMAL</DataType>
<Label>Contract Amount</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="3">
<Name>ContractCurrency</Name>
<Value>GBP</Value>
<DataType>STRING</DataType>
<Label>Contract Currency</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="4">
<Name>ContractLine</Name>
<Value>0030</Value>
<DataType>STRING</DataType>
<Label>Contract Line</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="5">
<Name>ContractManager</Name>
<Value>RDKORTE</Value>
<DataType>STRING</DataType>
<Label>Contract Manager</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="6">
<Name>ContractManagerName</Name>
<Value>Ron de Korte</Value>
<DataType>STRING</DataType>
<Label>Contract Manager Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="7">
<Name>ExternalSalesRepName</Name>
<Value>Jan Slag</Value>
<DataType>STRING</DataType>
<Label>External Sales Rep Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="8">
<Name>ExternalSalesRepresentative</Name>
<Value>JSLAG</Value>
<DataType>STRING</DataType>
<Label>External Sales Representative</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="9">
<Name>InternalSalesRepName</Name>
<Value>James Rea</Value>
<DataType>STRING</DataType>
<Label>Internal Sales Rep Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="10">
<Name>InternalSalesRepresentative</Name>
<Value>JREA</Value>
<DataType>STRING</DataType>
<Label>Internal Sales Representative</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="11">
<Name>LogicalId</Name>
<Value>lid://infor.ln.infor_ln_10_3_1_company_512</Value>
<DataType>STRING</DataType>
<Label>Logical Id</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="12">
<Name>SalesOffice</Name>
<Value>SBASUK</Value>
<DataType>STRING</DataType>
<Label>Sales Office</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="13">
<Name>SoldToBPName</Name>
<Value>BAES CS&S</Value>
<DataType>STRING</DataType>
<Label>Sold To BPName</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="14">
<Name>SoldToBusinessPartner</Name>
<Value>K0999</Value>
<DataType>STRING</DataType>
<Label>Sold To Business Partner</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="15">
<Name>SoldToContact</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Sold To Contact</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="16">
<Name>SoldToContactName</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Sold To Contact Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="17">
<Name>Status</Name>
<Value>20</Value>
<DataType>INTEGER</DataType>
<Label>Status</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="18">
<Name>StatusBeforeOnHold</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Status Before On Hold</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="19">
<Name>StatusOld</Name>
<Value>0</Value>
<DataType>INTEGER</DataType>
<Label>Status Old</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="20">
<Name>StatusOldName</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Status Old Name</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="21">
<Name>StatusPreviousOld</Name>
<Value>0</Value>
<DataType>INTEGER</DataType>
<Label>Status Previous Old</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="22">
<Name>SubmitUser</Name>
<Value>infor20</Value>
<DataType>STRING</DataType>
<Label>Submit User</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="23">
<Name>TaskUser</Name>
<Value/>
<DataType>STRING</DataType>
<Label>Task User</Label>
<ReadOnlyIndicator>true</ReadOnlyIndicator>
</Parameter>
<Parameter sequence="24">
<Name>WF_Reason</Name>
<Value/>
<DataType>STRING</DataType>
<Label>WF Reason</Label>
<ReadOnlyIndicator>false</ReadOnlyIndicator>
</Parameter>
<AssignedPerson>
<PersonReference>
<IDs>
<ID>mike.tollan@sharelnk30.net</ID>
</IDs>
</PersonReference>
</AssignedPerson>
<DistributionPerson>
<ID>768</ID>
<PersonReference>
<IDs>
<ID>mike.tollan@sharelnk30.net</ID>
</IDs>
<Name>Mike Tollan</Name>
<SystemUserIndicator>true</SystemUserIndicator>
</PersonReference>
</DistributionPerson>
</PulseTask>
</DataArea>
</SyncPulseTask>`
基本上我需要添加AssignedPerson节点 我怎么能这样做?
谢谢
答案 0 :(得分:1)
以这种方式尝试:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schema.infor.com/InforOAGIS/2"
xmlns:a="http://schema.infor.com/InforOAGIS/2"
exclude-result-prefixes="a">
<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="a:Parameter[not(following-sibling::a:Parameter)]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<AssignedPerson>
<PersonReference>
<IDs>
<ID>mike.tollan@sharelnk30.net</ID>
</IDs>
</PersonReference>
</AssignedPerson>
</xsl:template>
</xsl:stylesheet>
答案 1 :(得分:0)
由于你有一个默认的命名空间,你应该加上前缀,比如&#34; test&#34;并在稍后的xpath
中使用此前缀xmlns:test="http://schema.infor.com/InforOAGIS/2"
首先,您需要一个身份模板
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
然后,覆盖DistributionPerson
节点以包含所需的节点:
<xsl:template match="test:DistributionPerson">
<AssignedPerson>
<PersonReference>
<xsl:apply-templates select="test:PersonReference/test:IDs"/>
</PersonReference>
</AssignedPerson>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<强>样式表强>
<xsl:stylesheet version="1.0"
xmlns="http://schema.infor.com/InforOAGIS/2"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:test="http://schema.infor.com/InforOAGIS/2"
exclude-result-prefixes="test">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="test:DistributionPerson">
<AssignedPerson>
<PersonReference>
<xsl:apply-templates select="test:PersonReference/test:IDs"/>
</PersonReference>
</AssignedPerson>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
答案 2 :(得分:0)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:agis="http://schema.infor.com/InforOAGIS/2" exclude-result-prefixes="agis">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="agis:Parameter[last()]">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
<AssignedPerson>
<PersonReference>
<IDs>
<ID><xsl:value-of select="following-sibling::agis:DistributionPerson/agis:PersonReference/agis:IDs/agis:ID" /></ID>
</IDs>
</PersonReference>
</AssignedPerson>
</xsl:template>
</xsl:stylesheet>