XSLT 1.0-如果输入XML中没有值,则隐藏/抑制标签



我的情况与XSLT 1.0我需要删除输出XML中没有任何值xml

中没有任何值的标签。

这是源XML,如果您注意到第一个<Group Level:2>,而第一个<GroupFooter>部分确实具有任何值

<?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 Name="Field5" FieldName="{STATION.Item}"><FormattedValue>SH-Y20F</FormattedValue><Value>SH-Y20F</Value></Field>
<Text Name="Text30"><TextValue>Item</TextValue>
</Text>
<Field Name="Field6" FieldName="{INVENTRY.Description1}"><FormattedValue>Clear Lens CSA</FormattedValue><Value>Clear Lens CSA</Value></Field>
<Field Name="Field7" FieldName="{INVENTRY.Description2}"><FormattedValue>Schukra Of North Ame</FormattedValue><Value>Schukra Of North Ame</Value></Field>
<Text Name="Text31"><TextValue>Cost</TextValue>
</Text>
<Field Name="Field8" FieldName="{AltVendor.Cost}"><FormattedValue></FormattedValue><Value></Value></Field>
</Section>
</GroupHeader>
<Group Level="2">
<Details Level="3">
<Section SectionNumber="0">
<Field Name="Field9" FieldName="{STATION.Quantity}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field10" FieldName="{STATION.OnOrder}"><FormattedValue></FormattedValue><Value></Value></Field>
<Field Name="Field11" FieldName="{STATION.MonthlyUsage}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field12" FieldName="{STATION.OrderPoint}"><FormattedValue>7</FormattedValue><Value>7</Value></Field>
<Field Name="Field13" FieldName="{STATION.UsageThisMonth}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field14" FieldName="{STATION.BinQuantity}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field15" FieldName="{StationHistory.Prev1}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field16" FieldName="{StationHistory.Prev2}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field17" FieldName="{StationHistory.Prev3}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field18" FieldName="{StationHistory.Prev4}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field19" FieldName="{StationHistory.Prev5}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field20" FieldName="{StationHistory.Prev6}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field21" FieldName="{STATION.OrderNowQuantity}"><FormattedValue>12</FormattedValue><Value>12</Value></Field>
<Field Name="Field22" FieldName="{STATION.CribBin}"><FormattedValue>20-06-10</FormattedValue><Value>20-06-10</Value></Field>
<Field Name="Field23" FieldName="{STATION.Comments}"><FormattedValue></FormattedValue><Value></Value></Field>
</Section>
</Details>
</Group>
<GroupFooter>
<Section SectionNumber="0">
<Field Name="Field24" FieldName="Sum ({STATION.Quantity}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field25" FieldName="Sum ({STATION.OnOrder}, {STATION.Item})"><FormattedValue></FormattedValue><Value></Value></Field>
<Field Name="Field26" FieldName="Sum ({STATION.UsageThisMonth}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field27" FieldName="Sum ({STATION.OrderPoint}, {STATION.Item})"><FormattedValue>7</FormattedValue><Value>7.00</Value></Field>
<Field Name="Field28" FieldName="Sum ({STATION.MonthlyUsage}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field29" FieldName="Sum ({StationHistory.Prev6}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field30" FieldName="Sum ({StationHistory.Prev5}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field31" FieldName="Sum ({StationHistory.Prev4}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field32" FieldName="Sum ({StationHistory.Prev3}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field33" FieldName="Sum ({StationHistory.Prev2}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field34" FieldName="Sum ({StationHistory.Prev1}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field35" FieldName="Sum ({STATION.BinQuantity}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field36" FieldName="Sum ({STATION.OrderNowQuantity}, {STATION.Item})"><FormattedValue>12</FormattedValue><Value>12.00</Value></Field>
<Text Name="Text32"><TextValue>Summary</TextValue>
</Text>
<Field Name="Field37" FieldName="{INVENTRY.Comments}"><FormattedValue></FormattedValue><Value></Value></Field>
</Section>
</GroupFooter>
</Group>
<Group Level="1">
<GroupHeader>
<Section SectionNumber="0">
<Field Name="Field5" FieldName="{STATION.Item}"><FormattedValue>SH-Y20C</FormattedValue><Value>SH-Y20C</Value></Field>
<Text Name="Text30"><TextValue>Item</TextValue>
</Text>
<Field Name="Field6" FieldName="{INVENTRY.Description1}"><FormattedValue>OVER THE GLASSES - Visitor Spec,Clear Lens CSA</FormattedValue><Value>OVER THE GLASSES - Visitor Spec,Clear Lens CSA</Value></Field>
<Field Name="Field7" FieldName="{INVENTRY.Description2}"><FormattedValue>Schukra Of North Ame</FormattedValue><Value>Schukra Of North Ame</Value></Field>
<Text Name="Text31"><TextValue>Cost</TextValue>
</Text>
<Field Name="Field8" FieldName="{AltVendor.Cost}"><FormattedValue></FormattedValue><Value></Value></Field>
</Section>
</GroupHeader>
<Group Level="2">
<Details Level="3">
<Section SectionNumber="0">
<Field Name="Field9" FieldName="{STATION.Quantity}"><FormattedValue>6</FormattedValue><Value>6</Value></Field>
<Field Name="Field10" FieldName="{STATION.OnOrder}"><FormattedValue>0</FormattedValue><Value>0</Value></Field>
<Field Name="Field11" FieldName="{STATION.MonthlyUsage}"><FormattedValue>23</FormattedValue><Value>23</Value></Field>
<Field Name="Field12" FieldName="{STATION.OrderPoint}"><FormattedValue>10</FormattedValue><Value>10</Value></Field>
<Field Name="Field13" FieldName="{STATION.UsageThisMonth}"><FormattedValue>1</FormattedValue><Value>1</Value></Field>
<Field Name="Field14" FieldName="{STATION.BinQuantity}"><FormattedValue>6</FormattedValue><Value>6</Value></Field>
<Field Name="Field15" FieldName="{StationHistory.Prev1}"><FormattedValue>28</FormattedValue><Value>28</Value></Field>
<Field Name="Field16" FieldName="{StationHistory.Prev2}"><FormattedValue>22</FormattedValue><Value>22</Value></Field>
<Field Name="Field17" FieldName="{StationHistory.Prev3}"><FormattedValue>20</FormattedValue><Value>20</Value></Field>
<Field Name="Field18" FieldName="{StationHistory.Prev4}"><FormattedValue>20</FormattedValue><Value>20</Value></Field>
<Field Name="Field19" FieldName="{StationHistory.Prev5}"><FormattedValue>16</FormattedValue><Value>16</Value></Field>
<Field Name="Field20" FieldName="{StationHistory.Prev6}"><FormattedValue>30</FormattedValue><Value>30</Value></Field>
<Field Name="Field21" FieldName="{STATION.OrderNowQuantity}"><FormattedValue>4</FormattedValue><Value>4</Value></Field>
<Field Name="Field22" FieldName="{STATION.CribBin}"><FormattedValue>21-03-07</FormattedValue><Value>21-03-07</Value></Field>
<Field Name="Field23" FieldName="{STATION.Comments}"><FormattedValue>Y20C+EA</FormattedValue><Value>Y20C+EA</Value></Field>
</Section>
</Details>
</Group>
<GroupFooter>
<Section SectionNumber="0">
<Field Name="Field24" FieldName="Sum ({STATION.Quantity}, {STATION.Item})"><FormattedValue>11</FormattedValue><Value>11.00</Value></Field>
<Field Name="Field25" FieldName="Sum ({STATION.OnOrder}, {STATION.Item})"><FormattedValue>0</FormattedValue><Value>0.00</Value></Field>
<Field Name="Field26" FieldName="Sum ({STATION.UsageThisMonth}, {STATION.Item})"><FormattedValue>3</FormattedValue><Value>3.00</Value></Field>
<Field Name="Field27" FieldName="Sum ({STATION.OrderPoint}, {STATION.Item})"><FormattedValue>15</FormattedValue><Value>15.00</Value></Field>
<Field Name="Field28" FieldName="Sum ({STATION.MonthlyUsage}, {STATION.Item})"><FormattedValue>36</FormattedValue><Value>36.00</Value></Field>
<Field Name="Field29" FieldName="Sum ({StationHistory.Prev6}, {STATION.Item})"><FormattedValue>45</FormattedValue><Value>45.00</Value></Field>
<Field Name="Field30" FieldName="Sum ({StationHistory.Prev5}, {STATION.Item})"><FormattedValue>27</FormattedValue><Value>27.00</Value></Field>
<Field Name="Field31" FieldName="Sum ({StationHistory.Prev4}, {STATION.Item})"><FormattedValue>30</FormattedValue><Value>30.00</Value></Field>
<Field Name="Field32" FieldName="Sum ({StationHistory.Prev3}, {STATION.Item})"><FormattedValue>30</FormattedValue><Value>30.00</Value></Field>
<Field Name="Field33" FieldName="Sum ({StationHistory.Prev2}, {STATION.Item})"><FormattedValue>42</FormattedValue><Value>42.00</Value></Field>
<Field Name="Field34" FieldName="Sum ({StationHistory.Prev1}, {STATION.Item})"><FormattedValue>54</FormattedValue><Value>54.00</Value></Field>
<Field Name="Field35" FieldName="Sum ({STATION.BinQuantity}, {STATION.Item})"><FormattedValue>11</FormattedValue><Value>11.00</Value></Field>
<Field Name="Field36" FieldName="Sum ({STATION.OrderNowQuantity}, {STATION.Item})"><FormattedValue>9</FormattedValue><Value>9.00</Value></Field>
<Text Name="Text32"><TextValue>Summary</TextValue>
</Text>
<Field Name="Field37" FieldName="{INVENTRY.Comments}"><FormattedValue></FormattedValue><Value></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="substring-before(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>
                                        <xsl:value-of select="substring-after(cr:Group/cr:Details/cr:Section/cr:Field[@FieldName='{STATION.Comments}']/cr:Value,'+')"/>
                                    </SalesUnit>                 
                                </SalesLine>
                            </xsl:for-each> 
                        </SalesTable>               
                </SalesOrder>
            </MessageParts>
        </Body>
    </Envelope>
</xsl:template>
</xsl:stylesheet>

我不想要没有值的整个标签:

<SalesLine class="entity">
    <ItemId/>
    <SalesQty>0</SalesQty>
    <SalesUnit/>
</SalesLine>

预期:

<?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>Schukra Of North Ame</CustAccount>
                    <PurchOrderFormNum>PO</PurchOrderFormNum>
                    <ReceiptDateRequested>2019-08-02</ReceiptDateRequested>
                    <SalesLine class="entity">
                        <ItemId>Y20C</ItemId>
                        <SalesQty>11</SalesQty>
                        <SalesUnit>EA</SalesUnit>
                    </SalesLine>
                </SalesTable>
            </SalesOrder>
        </MessageParts>
    </Body>
</Envelope>

预先感谢您。

您可以通过更改来排除ItemIdSalesUnit值的组:

<xsl:for-each select="cr:Group">

to:

<xsl:value-of select="cr:Group/cr:GroupHeader/cr:Section/cr:Field[@FieldName='{INVENTRY.Description2}']/cr:Value"/> 

-
P.S.可以通过定义一些变量来使代码更加优雅 - 因此您不必多次重复相同的路径。

相关内容

  • 没有找到相关文章

最新更新