XSLT - 连接所有类似的Sube节点子值并在节点级别传递

时间:2013-12-18 19:18:47

标签: xslt-1.0

我的XML Logic中有类似的问题 我已经为我的XML requerd输出创建了XSLT,它运行正常,但有一点我无法填写 我在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:\0.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:\HM\Gwen\E1\IOT46110.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> 
  

这里我试图连接所有节点名称&#34;选项&#34;这将是N个时间的详细信息所以我们需要= Sequence + " - " + Code + " - " + Description (Option 1) + - Sequence + " - " + Code + " - " + Description (Option 2) - + Sequence + " - " + Code + " - " + Description (Option n) 这将适用于该标签中的所有选项。 请让我知道我必须在XSLT中做出哪些更改

1 个答案:

答案 0 :(得分:0)

您可以通过更换行

来使其工作
<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">