我在创建XSLT的模板匹配方式上一直遇到这个难题。我面临的问题是我正在创建的XSLT输入似乎有一些问题,该问题无法生成适当的转换后的xml。我无法弄清楚实际出了什么问题。
这是我的XML文件代码:-
<?xml version="1.0" encoding="utf-8"?>
<Materials xmlns="D.Manufacturing.Engineering">
<Changes>
<Material MaterialNumber="TEST_ID1">
<Plant>Pla1</Plant>
<Description>Description 1</Description>
<DescV>Description1 in V</DescV>
<UnitOfMeasurement>Kg</UnitOfMeasurement>
<MaterialGroup>MatGrp 1</MaterialGroup>
<MaterialGroupDesc>Kg</MaterialGroupDesc>
<TraceablePartIndicator>0</TraceablePartIndicator>
<KeyDataGroup>KeyDataGroup1</KeyDataGroup>
<Vendor>VendorID</Vendor>
<VendorName>VendorName1</VendorName>
<PackageQuantity>1</PackageQuantity>
<PackageNetWt>1</PackageNetWt>
<PackageUOM>nos</PackageUOM>
</Material>
<Material MaterialNumber="TEST_ID2">
<Plant>Pla2</Plant>
<Description>Description 2</Description>
<DescV>Description 2 in V</DescV>
<UnitOfMeasurement>Kg</UnitOfMeasurement>
<MaterialGroup>MatGrp 2</MaterialGroup>
<MaterialGroupDesc>Kg</MaterialGroupDesc>
<TraceablePartIndicator>0</TraceablePartIndicator>
<KeyDataGroup>KeyDataGroup1</KeyDataGroup>
<Vendor>VendorNID1</Vendor>
<VendorName>VendorName1</VendorName>
<PackageQuantity>1</PackageQuantity>
<PackageNetWt>1</PackageNetWt>
<PackageUOM>nos</PackageUOM>
</Material>
<Material MaterialNumber="TEST_ID3">
<Plant>Pla3</Plant>
<Description>Description 3</Description>
<DescV>Description 3 in V</DescV>
<UnitOfMeasurement>Kg</UnitOfMeasurement>
<MaterialGroup>MatGrp 3</MaterialGroup>
<MaterialGroupDesc>Kg</MaterialGroupDesc>
<TraceablePartIndicator>1</TraceablePartIndicator>
<KeyDataGroup>KeyDataGroup1</KeyDataGroup>
<Vendor>VendorNID1</Vendor>
<VendorName>VendorName1</VendorName>
<PackageQuantity>1</PackageQuantity>
<PackageNetWt>1</PackageNetWt>
<PackageUOM>nos</PackageUOM>
</Material>
</Changes>
<Deletes>
<DeleteMaterial MaterialNumber="ID10" />
<DeleteMaterial MaterialNumber="ID20" />
<DeleteMaterial MaterialNumber="ID30" />
</Deletes>
</Materials>
这是我的xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>
<xsl:template match="Materials[@xmlns='D.Manufacturing.Engineering']">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:trac="http://mes.com/TrackingCar">
<soapenv:Header />
<soapenv:Body>
<trac:MES_VEHICLE_STATUS_DESCRIPTOR>
<xsl:element name="ORDERHEADER">
<xsl:apply-templates select="/Materials/Changes/Material"/>
</xsl:element>
</trac:MES_VEHICLE_STATUS_DESCRIPTOR>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="/Materials/Changes/Material">
<xsl:element name="Material">
<xsl:element name="MaterialID">
<xsl:value-of select="@MaterialNumber"/>
</xsl:element>
<xsl:element name="Plant">
<xsl:value-of select="../Plant/text()"/>
</xsl:element>
<xsl:element name="Description">
<xsl:value-of select="../Description/text()"/>
</xsl:element>
<xsl:element name="DescV">
<xsl:value-of select="../DescV/text()"/>
</xsl:element>
<xsl:element name="UnitOfMeasurement">
<xsl:value-of select="../UnitOfMeasurement/text()"/>
</xsl:element>
<xsl:element name="MaterialGroup">
<xsl:value-of select="../MaterialGroup/text()"/>
</xsl:element>
<xsl:element name="MaterialGroupDesc">
<xsl:value-of select="../MaterialGroupDesc/text()"/>
</xsl:element>
<xsl:element name="TraceablePartIndicator">
<xsl:value-of select="../TraceablePartIndicator/text()"/>
</xsl:element>
<xsl:element name="KeyDataGroup">
<xsl:value-of select="../KeyDataGroup/text()"/>
</xsl:element>
<xsl:element name="Vendor">
<xsl:value-of select="../Vendor/text()"/>
</xsl:element>
<xsl:element name="VendorName">
<xsl:value-of select="../VendorName/text()"/>
</xsl:element>
<xsl:element name="PackageQuantity">
<xsl:value-of select="../PackageQuantity/text()"/>
</xsl:element>
<xsl:element name="PackageNetWt">
<xsl:value-of select="../PackageNetWt/text()"/>
</xsl:element>
<xsl:element name="PackageUOM">
<xsl:value-of select="../PackageUOM/text()"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我尝试了各种组合,但无法生成适当的xslt来获取转换后的XML。请让我知道问题出在哪里以及如何解决。