xmlnsNamesapce读取不正确XSLT中的问题没有正确转换文件



我为SSIS创建了一个XSLT,用于根据客户端需求将XML转换为XML。我在XSLT方面不是很擅长使用net帮助来解决这个问题。

现在,如果我删除xmlns="http://www.ofdaxml.org/schema">行但我正在寻找自动修复,因为我不能每次手动删除我们从clint获得的源文件,所以我不能在源文件中进行更改。

所以我想修复XSLT文件中唯一的

有人能帮我吗?

当前源文件

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://www.ofdaxml.org/schema C:PROGRA~1    HMIXMLOFDAOrder_03_00_00.xsd" xmlns="http://www.ofdaxml.org/schema"     SchemaVersion="03.00.00">
<Header>
<Vendor>
<Enterprise>
<Code>www.hermanmiller.com</Code>
</Enterprise>
<Code>CHM</Code>
</Vendor>
<Language>en-US</Language>
<Currency>CAD</Currency>
</Header>
<PurchaseOrder>
<Project>
<Title>Imp0.spe</Title>
<SpecifierFile>
<Name>W:KillerGwenE1It110.xml</Name>
<SpecifierSoftware Version="104.00">HM specIT</SpecifierSoftware>
</SpecifierFile>
<BusinessSoftware>HM specIT version 104.00</BusinessSoftware>
</Project>
<Header>
<PONumber>IT46_Room46110.spe</PONumber>
<TransactionCode>New</TransactionCode>
<CreatedDate>2013-11-29</CreatedDate>
<RequestedDate Type="DeliverOnOrBefore">2011-07-15</RequestedDate>
<BillType>Dealer</BillType>
<OrderType>99</OrderType>
<Contract>
<Code>CG1615</Code>
<Description>EP
</Description>
<SalesVolume Currency="INR">0</SalesVolume>
</Contract>
</Header>
<OrderLineItem>
<VendorRef EnterpriseRef="www.HM.com">HMI</VendorRef>
<Status>Complete</Status>
<Quantity>1</Quantity>
<LineItemNumber>2</LineItemNumber>
<SpecItem>
<Number>46-3620-69</Number>
<Description>+Stg Case Std Pull 36W 20D CaseHgt 65 5/8H</Description>
<Catalog>
<Code>MFS</Code>
</Catalog>
<Option Sequence="1">
<Code>XS</Code>
<Description>+textured paint on smooth steel</Description>
</Option>
<Option Sequence="2">
<Code>G1</Code>
<Description>+graphite</Description>
</Option>
<Option Sequence="6">
<Code>B1</Code>
<Description>+1 -high base</Description>
</Option>
</SpecItem>
</OrderLineItem>
</PurchaseOrder>
</Envelope>

当前XSLT文件

<xsl:stylesheet 
version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.ofdaxml.org/schema"> 
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="/Envelope"> 
<PurchaseOrder> 
<xsl:for-each select="PurchaseOrder/OrderLineItem"> 
<OrderLineDetails> 
<VendorRef><xsl:value-of select="VendorRef"/></VendorRef> 
<LineItemNumber><xsl:value-of select="LineItemNumber"/></LineItemNumber> 
<SpecItemNumber><xsl:value-of select="SpecItem/Number"/></SpecItemNumber> 
<SpecItemDesc><xsl:value-of select="SpecItem/Description"/></SpecItemDesc> 
<ITMOptionCode><xsl:value-of select="SpecItem/Option/Code"/></ITMOptionCode> 
<ITMOptionSeq><xsl:value-of select="SpecItem/Option/@Sequence"/></ITMOptionSeq> 
<ITMOptionDesc><xsl:value-of select="SpecItem/Option/Description"/></ITMOptionDesc> 
<ITMOptionCodeDescOld><xsl:value-of select="concat                (' ',SpecItem/Option/Code, ' ',SpecItem/Option/Description)"/></ITMOptionCodeDescOld> 
<ITMOptionCodeDesc>
<xsl:for-each select="SpecItem/Option">
<xsl:if test="position() > 1">
<xsl:text> - </xsl:text>
</xsl:if>
<xsl:value-of select="concat(@Sequence, ' - ',Code, ' - ',Description)"/>
</xsl:for-each>
</ITMOptionCodeDesc> 

</OrderLineDetails> 
</xsl:for-each> 
</PurchaseOrder> 
</xsl:template> 
</xsl:stylesheet>

我已经更改了我的XSLT文件,但仍然出现错误。

当前XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:ofda="http://www.ofdaxml.org/schema"
xmlns="http://www.ofdaxml.org/schema" exclude-result-prefixes="ofda">
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="/Envelope"> 
<PurchaseOrder> 
<xsl:for-each select="ofda:PurchaseOrder/OrderLineItem"> 
<OrderLineDetails> 
<VendorRef><xsl:value-of select="ofda:VendorRef"/></VendorRef> 
<LineItemNumber><xsl:value-of select="ofda:LineItemNumber"/></LineItemNumber> 
<SpecItemNumber><xsl:value-of select="ofda:SpecItem/Number"/></SpecItemNumber> 
<SpecItemDesc><xsl:value-of select="ofda:SpecItem/Description"/></SpecItemDesc> 
<ITMOptionCode><xsl:value-of select="ofda:SpecItem/Option/Code"/></ITMOptionCode> 
<ITMOptionSeq><xsl:value-of select="ofda:SpecItem/Option/@Sequence"/></ITMOptionSeq> 
<ITMOptionDesc><xsl:value-of     select="ofda:SpecItem/Option/Description"/></ITMOptionDesc> 
<ITMOptionCodeDescOld><xsl:value-of select="concat                (' ',ofda:SpecItem/Option/Code, ' ',ofda:SpecItem/Option/Description)"/></ITMOptionCodeDescOld> 
<ITMOptionCodeDesc>
<xsl:for-each select="ofda:SpecItem/Option">
<xsl:if test="position() > 1">
<xsl:text> - </xsl:text>
</xsl:if>
<xsl:value-of select="concat(@Sequence, ' - ',ofda:Code, ' - ',ofda:Description)"/>
</xsl:for-each>
</ITMOptionCodeDesc> 
</OrderLineDetails> 
</xsl:for-each> 
</PurchaseOrder> 
</xsl:template> 
</xsl:stylesheet>

电流输出

<?xml version="1.0" encoding="utf-8"?>www.hr.comCHMen-USCADImperialOil_Trailer46_Room46110.speW:hrGwenE1ImperialOil_Trailer46110.xmlHMspecITHMspecIT version 104.00ImperialOil_Trailer46_Room46110.speNew2013-11-292011-07-15Dealer99CG1615Exxon Mobil Global Svcs.Co.-CANADA0HMIComplete1160.0060.0018.0018.0015.0015.00FT75.0070.00FT199.+Cable Management TroughHFTHMIComplete121157.001157.00557.93557.93428.09428.09MS63.0051.77846-3620-69+Stg Case Std Pull 36W 20D CaseHgt 65 5/8HMFSXS+textured paint on smooth steelG1+graphiteW+coat rod with 3 shelves (only available with T2 top)KD+keyed differently  blackT2+1 1/4 -high painted metal top with squared edgeB1+1 -high baseHMIComplete131844.001844.00922.00922.00737.60737.60MF605026-3620-4+Lateral File Std Pull 4-High 36W 20DMERXS+textured paint on smooth steelG1+graphiteT1+1 -high painted metal top with squared edgeOH+overhead hinged door 26-1/4NS1+1 shelf totalKD+keyed differently  blackE+fixed front 13-1/89R+side-to-side filing railKD+keyed differently  blackE+fixed front 13-1/89R+side-to-side filing railE+fixed front 13-1/89R+side-to-side filing railCB+counterweightB1+Base 1 in HHMIComplete14626.00626.00194.06194.06162.76162.76UP74.0069.00LW120.20BF+Mobile Pedastool W-Pull 20D B/FHTUSR+3/4-extension roller slides on box drawers  full-extension ball bearing on file drawerXS+textured paint on smooth steelG1+graphite8T+crossing-Pr Cat 118+crossing indigoH1+hand gripKD+keyed differently  black5M+pencil tray in box drawer  2 file converters in file drawerHMIComplete152485.712485.711491.431491.43745.71745.71FT7040NXLR6630E1S+Work Surf Sq-Edge Rectangular Lam 30D 66WBKR28+canyonEdgeWNBaseblackHMIComplete16757.00757.00319.45319.45267.22267.22ZZ64.7057.80Workrite monitor armMonitor arm with extended arm WRT0I@silverHMIComplete17440.00440.00440.00440.00308.00308.00300InstallationInstallation ChargeCHA

尽管如此,我还是遇到了同样的问题,我不知道我缺少了什么部分Updatd文件

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:ofda="http://www.ofdaxml.org/schema"
xmlns="http://www.ofdaxml.org/schema" exclude-result-prefixes="ofda">
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="ofda:Enveloper"> 
<PurchaseOrder> 
<xsl:for-each select="ofda:PurchaseOrder/OrderLineItem"> 
<OrderLineDetails> 
<VendorRef><xsl:value-of select="ofda:VendorRef"/></VendorRef> 
<LineItemNumber><xsl:value-of select="ofda:LineItemNumber"/></LineItemNumber> 
<SpecItemNumber><xsl:value-of select="ofda:SpecItem/Number"/></SpecItemNumber> 
<SpecItemDesc><xsl:value-of select="ofda:SpecItem/Description"/></SpecItemDesc> 
<ITMOptionCode><xsl:value-of select="ofda:SpecItem/Option/Code"/></ITMOptionCode> 
<ITMOptionSeq><xsl:value-of select="ofda:SpecItem/Option/@Sequence"/></ITMOptionSeq> 
<ITMOptionDesc><xsl:value-of     select="ofda:SpecItem/Option/Description"/></ITMOptionDesc> 
<ITMOptionCodeDescOld><xsl:value-of select="concat            (' ',ofda:SpecItem/Option/Code, ' ',ofda:SpecItem/Option/Description)"/></ITMOptionCodeDescOld> 
<ITMOptionCodeDesc>
<xsl:for-each select="ofda:SpecItem/Option">
<xsl:if test="position() > 1">
<xsl:text> - </xsl:text>
</xsl:if>
<xsl:value-of select="concat(@Sequence, ' - ',ofda:Code, ' - ',ofda:Description)"/>
</xsl:for-each>
</ITMOptionCodeDesc> 
</OrderLineDetails> 
</xsl:for-each> 
</PurchaseOrder> 
</xsl:template> 
</xsl:stylesheet>

请让我知道我必须在哪里更换

您应该阅读一些关于XML/XXSLT和名称空间的文章。

您的输入XML有一个声明为xmlns="http://www.ofdaxml.org/schema"的默认命名空间。这意味着所有未固定的元素都属于此命名空间。

因此,您还应该在XSLT中声明名称空间。首选带有前缀的。您现在只将其声明为默认名称空间,但将其作为前缀。

更改

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.ofdaxml.org/schema">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ofda="http://www.ofdaxml.org/schema" xmlns="http://www.ofdaxml.org/schema" exclude-result-prefixes="pfda">

上面的命名空间声明意味着:

  • 输入XML中所有未加前缀的元素都与XSLT中带前缀的元素相匹配。您可以使用此前缀从输入XML中选择元素,如odfa:Envelope
  • XSLT中的默认名称空间用于在XSLT中创建的所有新元素注意:您可以省略默认值,但应该为所有新创建的元素添加前缀

exclude-result-prefixes="odfa"不会将名称空间输出到结果XML中。现在您已经用前缀声明了名称空间,并且您可以用这个前缀选择属于这个名称空间的节点,如下所示:

<xsl:template match="/odfa:Envelope"> 
<xsl:for-each select="odfa:PurchaseOrder/odfa:OrderLineItem"> 
<VendorRef><xsl:value-of select="odfa:VendorRef"/></VendorRef> 

相关内容

  • 没有找到相关文章

最新更新