我的XML文件是这样的:编辑两个XML文件
<CompletePPCallback>
<MessageId>9133235059913398501</MessageId>
<keyB>keyBkeyBkeyB</keyB>
<filename>c:\temp\log\SMKFFcompleteProductionPlan.xml</filename>
</CompletePPCallback>
如果标签“文件名”是通向另一个XML文件。这个文件的例子:
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<ns2:completeProductionPlan
xmlns='http://ServiceManagement/OIS_Services_v01.00/common'
xmlns:ns2='http://ServiceManagement/TechnicalOrderManagement/ProductionFulfillment_v01.00/types'>
<ns2:messageID>
<value>9133235059913398501_9133235059913398860</value>
</ns2:messageID>
</ns2:completeProductionPlan>
</soapenv:Body>
</soapenv:Envelope>
现在我需要创建XSL文件,将复制第二个XML文件,并从第一个XML文件改变MESSAGEID的价值。例如:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="http://ServiceManagement/TechnicalOrderManagement/ProductionFulfillment_v01.00/types"
xmlns:common="http://ServiceManagement/OIS_Services_v01.00/common"
exclude-result-prefixes="ns2 common">
<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes" />
<xsl:variable name="providerXMLpath">
<xsl:value-of select="//filename" />
</xsl:variable>
<xsl:variable name="providerMessageId">
<xsl:value-of select="document($providerXMLpath)//ns2:messageID/common:value" />
</xsl:variable>
<copy>
<xsl:copy-of select="document($providerXMLpath)"/>
</copy>
<xsl:template match="/">
<FirstTag>
<xsl:choose>
<xsl:when test='$providerMessageId=//MessageId'>
<tag>
<xsl:text>Equal</xsl:text>
</tag>
</xsl:when>
<xsl:otherwise>
<tag>
<xsl:text>Different</xsl:text>
</tag>
</xsl:otherwise>
</xsl:choose>
</FirstTag>
</xsl:template>
</xsl:stylesheet>
如何更改复制xml文件的值?
编辑。 输出XML我想:
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<ns2:completeProductionPlan
xmlns='http://ServiceManagement/OIS_Services_v01.00/common'
xmlns:ns2='http://ServiceManagement/TechnicalOrderManagement/ProductionFulfillment_v01.00/types'>
<ns2:messageID>
<value>9133235059913398501</value>
</ns2:messageID>
</ns2:completeProductionPlan>
</soapenv:Body>
</soapenv:Envelope>
二更新:
Now I have this xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:completeProductionPlan
xmlns="http://ServiceManagement/OIS_Services_v01.00/common"
xmlns:ns2="http://ServiceManagement/TechnicalOrderManagement/ProductionFulfillment_v01.00/types">
<ns2:messageID>
<value>9133235059913398501_9133235059913398860</value>
</ns2:messageID>
<ns2:productionPlan>
<entityKey>
<keyA>9c4332b3-e60d-466b-9ab8-1187e98582e9</keyA>
</entityKey>
<state>
<value>readyForCompletion</value>
</state>
<service>
<entityKey>
<keyB>f51c2436-1a8e-4411-9a95-4eed04bcb412</keyB>
</entityKey>
<specification>
<specificationName>Access_Line</specificationName>
<specificationID>Access_Line</specificationID>
<characteristic>
<characteristicID>SpecificationType</characteristicID>
<characteristicValue>RFS</characteristicValue>
</characteristic>
</specification>
</service>
<service>
<entityKey>
<keyB>29b81be7-94e0-47e7-82f7-884ad57755d7</keyB>
</entityKey>
<specification>
<specificationName>Workforce_Recherche</specificationName>
<specificationID>Workforce_Recherche</specificationID>
<characteristic>
<characteristicID>SpecificationType</characteristicID>
<characteristicValue>RFS</characteristicValue>
</characteristic>
</specification>
</service>
</ns2:productionPlan>
</ns2:completeProductionPlan>
</soapenv:Body>
</soapenv:Envelope>
我想通过值从这个最后的代码示例替换“KEYB”标签值“KEYB”标签( “keyBkeyBkeyB”),如果其子标签'specificationName'等于Workforce_Recherche的值。我可以使用身份模板吗?我有几个标签'keyB'和'specificationName',但只需要使用上述属性更改一个值。
我想:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:completeProductionPlan
xmlns="http://ServiceManagement/OIS_Services_v01.00/common"
xmlns:ns2="http://ServiceManagement/TechnicalOrderManagement/ProductionFulfillment_v01.00/types">
<ns2:messageID>
<value>9133235059913398501</value>
</ns2:messageID>
<ns2:productionPlan>
<entityKey>
<keyA>9c4332b3-e60d-466b-9ab8-1187e98582e9</keyA>
</entityKey>
<state>
<value>readyForCompletion</value>
</state>
<service>
<entityKey>
<keyB>f51c2436-1a8e-4411-9a95-4eed04bcb412</keyB>
</entityKey>
<specification>
<specificationName>Access_Line</specificationName>
<specificationID>Access_Line</specificationID>
<characteristic>
<characteristicID>SpecificationType</characteristicID>
<characteristicValue>RFS</characteristicValue>
</characteristic>
</specification>
</service>
<service>
<entityKey>
<keyB>keyBkeyBkeyB</keyB>
</entityKey>
<specification>
<specificationName>Workforce_Recherche</specificationName>
<specificationID>Workforce_Recherche</specificationID>
<characteristic>
<characteristicID>SpecificationType</characteristicID>
<characteristicValue>RFS</characteristicValue>
</characteristic>
</specification>
</service>
</ns2:productionPlan>
</ns2:completeProductionPlan>
</soapenv:Body>
</soapenv:Envelope>
你要保持你的第二个XML中生成的输出,因为它是除了一些在ns2中更改:messageID/value元素? –
我想从第一个xml的MessageId标记值中替换ns2:messageID/value。一般来说,我想知道如何编辑复制xml标记和值:添加新标记,更改值等。 – turlife
您能否为预期的输出xml添加示例。 –