xslt 2.0 Mapping(如何根据循环中的条件获取字段的相关值)

时间:2017-04-15 04:25:26

标签: xslt-2.0

我正在尝试将IDOC xml转换为cXml。有一个重复节点E1EDKA1,它有PARVW,PARTN。基于PARVW =' AG'我需要提取值PARTN = 3000。但对我来说,PARTN = 3000 00001000中会出现多个值。

{Find the xsl logic as below:}

    <cXML>
    <Request>
    <OrderRequest>
    <OrderRequestHeader>
    <xsl:for-each select="//E1EDKA1/PARVW='AG'">
    <ShipTo>
     <Address>
      <Name>                
       <xsl:attribute name="xml:lang">
          <xsl:value-of select="//PARTN"/>
       </xsl:attribute>                
      </Name>
    </Address>
   </ShipTo>
   </xsl:for-each>
  </OrderRequestHeader>
  </OrderRequest>
  </Request>
  </cXML>

{This is the Source xml}
    <_-ARBA_-ORDERS>
   <IDOC BEGIN="1">
      <E1EDKA1 SEGMENT="1">
         <PARVW>AG</PARVW>
         <PARTN>3000</PARTN>
         <TELF1>069/5511</TELF1>
         <BNAME>Dickens, B.</BNAME>
         <PAORG>3000</PAORG>
         <ORGTX>PurchOrg US</ORGTX>
         <PAGRU>001</PAGRU>
      </E1EDKA1>
      <E1EDKA1 SEGMENT="1">
         <PARVW>LF</PARVW>
         <PARTN>0000001000</PARTN>
         <SPRAS>E</SPRAS>
         <SPRAS_ISO>EN</SPRAS_ISO>
      </E1EDKA1>
      <E1EDKA1 SEGMENT="1">
         <PARVW>WE</PARVW>
         <LIFNR>3000</LIFNR>
         <NAME1>New York</NAME1>
         <NAME2>New York</NAME2>
         <STRAS>691 Broadway</STRAS>
         <PFACH>5454545</PFACH>
         <ORT01>NEW YORK</ORT01>
         <PSTLZ>10001</PSTLZ>
         <LAND1>US</LAND1>
         <TELF1>001-9287-34571</TELF1>
         <TELFX>001-9287-34573</TELFX>
         <SPRAS>E</SPRAS>
         <ORT02>NEW YORK</ORT02>
         <REGIO>NY</REGIO>
         <SPRAS_ISO>EN</SPRAS_ISO>
      </E1EDKA1>
   </IDOC>
</_-ARBA_-ORDERS>

 Please help me out to get single value based on the condition.

2 个答案:

答案 0 :(得分:1)

<xsl:for-each select="//E1EDKA1/PARVW='AG'">更改为<xsl:for-each select="//E1EDKA1[PARVW='AG']">,然后更改

  <Name>                
   <xsl:attribute name="xml:lang">
      <xsl:value-of select="//PARTN"/>
   </xsl:attribute>                
  </Name>

  <Name>                
   <xsl:attribute name="xml:lang">
      <xsl:value-of select="PARTN"/>
   </xsl:attribute>                
  </Name>

答案 1 :(得分:0)

感谢Martin的回复。我试着用这种方式工作:

<xsl:for-each select="/_-ARBA_-ORDERS/IDOC/E1EDKA1">
            <xsl:if test="PARVW='AG'">
              <xsl:attribute name="xml:lang">
                <xsl:value-of select="PARTN"/>
              </xsl:attribute>
             </xsl:if>
             </xsl:for-each>