我有這個源XML:插入部分插入XML文檔
<?xml version="1.0" encoding="UTF-8"?>
<SyncSupplierInvoice xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" languageCode="en-US" releaseID="9.2" systemEnvironmentCode="Production" versionID="2.8.0">
<UserArea>
<Property>
<NameValue name="TypeCode">PS</NameValue>
</Property>
<Property>
<NameValue name="TaxCode">TGPLG180</NameValue>
</Property>
<Property>
<NameValue name="TaxOrg">*</NameValue>
</Property>
</UserArea>
</SyncSupplierInvoice>
有3在UserArea物業部分。我想插入第4部分,customTaxCode,它包含TaxCode的最後一個字符。像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<SyncSupplierInvoice xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" languageCode="en-US" releaseID="9.2" systemEnvironmentCode="Production" versionID="2.8.0">
<UserArea>
<Property>
<NameValue name="TypeCode">PS</NameValue>
</Property>
<Property>
<NameValue name="TaxCode">TGPLG180</NameValue>
</Property>
<Property>
<NameValue name="customTaxCode">0</NameValue>
</Property>
<Property>
<NameValue name="TaxOrg">*</NameValue>
</Property>
</UserArea>
</SyncSupplierInvoice>
我的XSLT只能部分工作。問題在於它在現有的Property元素下創建Property元素,而不是作爲兄弟。我不知道如何實現結果。提前感謝您的任何建議。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://schema.infor.com/InforOAGIS/2" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<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="//my:UserArea/my:Property/my:NameValue[@name='TaxCode']">
<xsl:copy-of select="."/>
<Property>
<NameValue name="customTaxCode">
<xsl:value-of select="substring(., string-length(.), 1)" />
</NameValue>
</Property>
</xsl:template>
</xsl:stylesheet>