XSLT 1.0-使用定界符在for语言 - EAPE循环中拆分字段



我有一个需要转换的XML文件。我能够构建在第一个方案中无限制的XSLT文件,但现在在第二种情况下,有一个定界线 字段,需要分为两个字段。

这是我第二种情况中的源XML;可分配者 在" group/group/详细信息/section/field/'fieldname ='{station.comments}'/value"字段:

<?xml version="1.0" encoding="UTF-8"?>
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd">
   <Group Level="1">
      <GroupHeader>
         <Section SectionNumber="0">
            <Field FieldName="{STATION.Item}" Name="Field5">
               <FormattedValue>TR-BP169-10</FormattedValue>
               <Value>TR-BP169-10</Value>
            </Field>
            <Text Name="Text30">
               <TextValue>Item</TextValue>
            </Text>
            <Field FieldName="{INVENTRY.Description2}" Name="Field7">
                <FormattedValue>TRW Automotive</FormattedValue>
                <Value>TRW Automotive</Value>
            </Field>
         </Section>
      </GroupHeader>
      <Group Level="2">
         <Details Level="3">
            <Section SectionNumber="0">
               <Field FieldName="{STATION.Quantity}" Name="Field9">
                  <FormattedValue>11</FormattedValue>
                  <Value>11</Value>
               </Field>
               <Field FieldName="{STATION.Comments}" Name="Field23">
                    <FormattedValue>SWBP169-10</FormattedValue>
                    <Value>SWBP169-10+EA</Value>
                </Field>
            </Section>
         </Details>
      </Group>
      <GroupFooter>
         <Section SectionNumber="0">
            <Field FieldName="Sum ({STATION.Quantity}, {STATION.Item})" Name="Field24">
               <FormattedValue>47</FormattedValue>
               <Value>47.00</Value>
            </Field>
         </Section>
      </GroupFooter>
   </Group>
   <Group Level="1">
      <GroupHeader>
         <Section SectionNumber="0">
            <Field FieldName="{STATION.Item}" Name="Field5">
               <FormattedValue>TR-Y19CFC</FormattedValue>
               <Value>TR-Y19CFC</Value>
            </Field>
            <Text Name="Text30">
               <TextValue>Item</TextValue>
            </Text>
            <Field FieldName="{INVENTRY.Description2}" Name="Field7">
                <FormattedValue>TRW Automotive</FormattedValue>
                <Value>TRW Automotive</Value>
            </Field>
         </Section>
      </GroupHeader>
      <Group Level="2">
         <Details Level="3">
            <Section SectionNumber="0">
               <Field FieldName="{STATION.Quantity}" Name="Field9">
                  <FormattedValue>9</FormattedValue>
                  <Value>9</Value>
               </Field>
               <Field FieldName="{STATION.Comments}" Name="Field23">
                    <FormattedValue>Y19CFC</FormattedValue>
                    <Value>Y19CFC+EA</Value>
                </Field>
            </Section>
         </Details>
      </Group>
      <GroupFooter>
         <Section SectionNumber="0">
            <Field FieldName="Sum ({STATION.Quantity}, {STATION.Item})" Name="Field24">
               <FormattedValue>18</FormattedValue>
               <Value>18.00</Value>
            </Field>
         </Section>
      </GroupFooter>
   </Group>
</CrystalReport>

这是我的XSLT 1.0文件,在第一个方案中,没有添加分配器:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cr="urn:crystal-reports:schemas:report-detail"
exclude-result-prefixes="cr msxsl cs"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:cs="urn:cs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<msxsl:script language="C#" implements-prefix="cs">
<![CDATA[
    public string datenow()
    {
        return(DateTime.Now.ToString("yyyy'-'MM'-'dd"));
    }
    ]]>
</msxsl:script>
<xsl:template match="/cr:CrystalReport">
    <Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
        <Header>
            <Company>tgs</Company>
            <Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesOrderService/create</Action>
        </Header>
        <Body>
            <MessageParts>
                <SalesOrder xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder">
                        <SalesTable class="entity">
                            <CustAccount>                               
                                <xsl:value-of select="cr:Group/cr:GroupHeader/cr:Section/cr:Field[@FieldName='{INVENTRY.Description2}']/cr:Value"/>                             
                            </CustAccount>
                        <PurchOrderFormNum>PO</PurchOrderFormNum>
                        <ReceiptDateRequested><xsl:value-of select="cs:datenow()"/></ReceiptDateRequested>                  
                        <!-- sale lines -->                                             
                            <xsl:for-each select="cr:Group">
                                <SalesLine class="entity">                          
                                    <ItemId>
                                        <xsl:value-of select="cr:Group/cr:Details/cr:Section/cr:Field[@FieldName='{STATION.Comments}']/cr:Value"/>
                                    </ItemId>              
                                    <SalesQty>
                                        <xsl:value-of select="cr:GroupFooter/cr:Section/cr:Field[@FieldName='Sum ({STATION.Quantity}, {STATION.Item})']/cr:FormattedValue"/>                   
                                    </SalesQty> 
                                    <SalesUnit>EA</SalesUnit>                 
                                </SalesLine>
                            </xsl:for-each> 
                        </SalesTable>               
                </SalesOrder>
            </MessageParts>
        </Body>
    </Envelope>
</xsl:template>
</xsl:stylesheet>

这是使用定界符的单独字段的所需输出。定界符用于创建两个字段,以用于ITEMID,第二个字段用于Salesunit:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
    <Header>
        <Company>tgs</Company>
        <Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesOrderService/create</Action>
    </Header>
    <Body>
        <MessageParts>
            <SalesOrder xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder">
                <SalesTable class="entity">
                    <CustAccount>TRW Automotive</CustAccount>
                    <PurchOrderFormNum>PO</PurchOrderFormNum>
                    <ReceiptDateRequested>2019-08-01</ReceiptDateRequested>
                    <SalesLine class="entity">
                        <ItemId>SWBP169-10</ItemId>
                        <SalesQty>47</SalesQty>
                        <SalesUnit>EA</SalesUnit>
                    </SalesLine>
                    <SalesLine class="entity">
                        <ItemId>Y19CFC</ItemId>
                        <SalesQty>18</SalesQty>
                        <SalesUnit>EA</SalesUnit>
                    </SalesLine>
                </SalesTable>
            </SalesOrder>
        </MessageParts>
    </Body>
</Envelope>

预先感谢。

如果源将始终包含两个由 +隔开的值,则可以使用:

提取第一个值
substring-before(Value, '+')

和第二个由:

substring-after(Value, '+')

相关内容

  • 没有找到相关文章

最新更新