XSLT - 连接所有类似的 sube 节点子值并在节点拉维尔传递

  • 本文关键字:节点 XSLT 连接 sube xslt-1.0
  • 更新时间 :
  • 英文 :


我的XML逻辑中有类似的问题我已经为我的 XML requrd 输出创建了 XSLT,它工作正常,但有一点我无法 filx我在 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:.xsd"  xmlns="http://www.ofdaxml.org/schema" SchemaVersion="03.00.00"> 
<Header> 
<Vendor> 
<Enterprise> 
<Code>www.HM.com</Code> 
</Enterprise> 
<Code>CHM</Code> 
</Vendor> 
<Language>en-US</Language> 
<Currency>INR</Currency> 
</Header> 
<PurchaseOrder> 
<Project> 
<Title>IOT46_Room46110.spe</Title> 
<SpecifierFile> 
<Name>W:HMGwenE1IOT46110.xml</Name> 
<SpecifierSoftware Version="104.00">Herman Miller specIT</SpecifierSoftware> 
</SpecifierFile> 
<BusinessSoftware>HME.00</BusinessSoftware> 
</Project> 
<Header> 
<PONumber>IOT46_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>Exxon Mobil Global Svcs.Co.-CANADA</Description> 
<SalesVolume Currency="USD">0</SalesVolume> 
</Contract> 
</Header> 
<OrderLineItem> 
<VendorRef EnterpriseRef="www.HM.com">HMI</VendorRef> 
<Status>Complete</Status> 
<Quantity>1</Quantity> 
<LineItemNumber>1</LineItemNumber> 
<Price> 
<PublishedPrice>60.00</PublishedPrice> 
<PublishedPriceExt>60.00</PublishedPriceExt> 
<EndCustomerPrice>18.00</EndCustomerPrice> 
<EndCustomerPriceExt>18.00</EndCustomerPriceExt> 
<OrderDealerPrice>15.00</OrderDealerPrice> 
<OrderDealerPriceExt>15.00</OrderDealerPriceExt> 
<DiscountCategory>FT</DiscountCategory> 
<OrderDealerDiscount>75.00</OrderDealerDiscount> 
<EndCustomerDiscount>70.00</EndCustomerDiscount> 
</Price> 
<SpecItem> 
<Number>FT199.</Number> 
<Description>+Cable Management Trough</Description> 
<Catalog>     
<Code>HFT</Code> 
</Catalog> 
</SpecItem> 
</OrderLineItem> 
<OrderLineItem> 
<VendorRef EnterpriseRef="www.HM.com">HMI</VendorRef> 
<Status>Complete</Status> 
<Quantity>1</Quantity> 
<LineItemNumber>2</LineItemNumber> 
<Price> 
<PublishedPrice>1157.00</PublishedPrice> 
<PublishedPriceExt>1157.00</PublishedPriceExt> 
<EndCustomerPrice>557.93</EndCustomerPrice> 
<EndCustomerPriceExt>557.93</EndCustomerPriceExt> 
<OrderDealerPrice>428.09</OrderDealerPrice> 
<OrderDealerPriceExt>428.09</OrderDealerPriceExt> 
<DiscountCategory>MS</DiscountCategory> 
<OrderDealerDiscount>63.00</OrderDealerDiscount> 
<EndCustomerDiscount>51.778</EndCustomerDiscount> 
</Price> 
<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="3"> 
<Code>W</Code> 
<Description>+coat rod with 3 shelves (only available with T2 top)</Description> 
</Option> 
<Option Sequence="4"> 
<Code>KD</Code> 
<Description>+keyed differently black</Description> 
</Option> 
<Option Sequence="5"> 
<Code>T2</Code> 
<Description>+1 1/4 -high painted metal top with squared edge</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"> 
<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> 
<ITMOptionCodeDesc><xsl:value-of select="concat            (' ',SpecItem/Option/Code, ' ',SpecItem/Option/Description)"/></ITMOptionCodeDesc> 
</OrderLineDetails> 
</xsl:for-each> 
</PurchaseOrder> 
</xsl:template> 
</xsl:stylesheet> 
    

电流输出如下 

<?xml version="1.0" encoding="utf-8"?> 
<PurchaseOrder> 
<OrderLineDetails> 
<VendorRef>HMI</VendorRef> 
<LineItemNumber>1</LineItemNumber> 
<SpecItemNumber>FT199.</SpecItemNumber> 
<SpecItemDesc>+Cable Management Trough</SpecItemDesc> 
<ITMOptionCode></ITMOptionCode> 
<ITMOptionSeq></ITMOptionSeq> 
<ITMOptionDesc></ITMOptionDesc> 
<ITMOptionCodeDesc> </ITMOptionCodeDesc> 
</OrderLineDetails> 
<OrderLineDetails> 
<VendorRef>HMI</VendorRef> 
<LineItemNumber>2</LineItemNumber> 
<SpecItemNumber>46-3620-69</SpecItemNumber> 
<SpecItemDesc>+Stg Case Std Pull 36W 20D CaseHgt 65 5/8H</SpecItemDesc> 
<ITMOptionCode>XS</ITMOptionCode> 
<ITMOptionSeq>1</ITMOptionSeq> 
<ITMOptionDesc>+textured paint on smooth steel</ITMOptionDesc> 
<ITMOptionCodeDesc> XS +textured paint on smooth steel</ITMOptionCodeDesc> 
</OrderLineDetails> 
</PurchaseOrder> 
  

预期输出如下

<?xml version="1.0" encoding="utf-8"?> 
<PurchaseOrder> 
<OrderLineDetails> 
<VendorRef>HMI</VendorRef> 
<LineItemNumber>1</LineItemNumber> 
<SpecItemNumber>FT199.</SpecItemNumber> 
<SpecItemDesc>+Cable Management Trough</SpecItemDesc> 
<ITMOptionCode></ITMOptionCode> 
<ITMOptionSeq></ITMOptionSeq> 
<ITMOptionDesc></ITMOptionDesc> 
<ITMOptionCodeDesc></ITMOptionCodeDesc> 
</OrderLineDetails> 
<OrderLineDetails> 
<VendorRef>HMI</VendorRef> 
<LineItemNumber>2</LineItemNumber> 
<SpecItemNumber>46-3620-69</SpecItemNumber> 
<SpecItemDesc>+Stg Case Std Pull 36W 20D CaseHgt 65 5/8H</SpecItemDesc> 
<ITMOptionCode>XS</ITMOptionCode> 
<ITMOptionSeq>1</ITMOptionSeq> 
<ITMOptionDesc>+textured paint on smooth steel</ITMOptionDesc> 
<ITMOptionCodeDesc>1 - XS - +textured paint on smooth steel - 2 - G1 - +graphite - 3 -     W - +coat rod with 3 shelves (only available with T2 top) - 4 - KD - +keyed     differently black - 5- T2 -+1 1/4 -high painted metal top with squared edge - 6 - B1 - +1 -    high base</ITMOptionCodeDesc> 
</OrderLineDetails> 
</PurchaseOrder> 
  

在这里,我试图简洁所有节点名称"选项",它将是N次详细,因此我们需要= Sequence + " - " + Code + " - " + Description (Option 1) + - Sequence + " - " + Code + " - " + Description (Option 2) - + Sequence + " - " + Code + " - " + Description (Option n)逻辑这将适用于该标签中的所有选项。请让我知道必须在 XSLT 中进行哪些更改

您可以通过替换行来使其工作

<ITMOptionCodeDesc><xsl:value-of select="concat            (' ',SpecItem/Option/Code, ' ',SpecItem/Option/Description)"/></ITMOptionCodeDesc> 

<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> 

该解决方案循环访问所有选项,并一次写出每个选项。<xsl:if> 标记用于在第一个选项之前禁止显示分隔符。

编辑

由于输入文件使用默认的命名空间声明(并且无法在那里删除),因此必须在样式表中添加声明:

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

相关内容

  • 没有找到相关文章

最新更新