简体   繁体   English

从 XML 中获取值 Node from XML SSRS Report 中的数据源是否存在其他节点值

[英]Get value from XML Node from XML Data source in SSRS Report if another node value exists

I have a Report (.rdl) file that uses an XML data source.我有一个使用 XML 数据源的报告 (.rdl) 文件。 One of the XML nodes is 'Tax' that I need to display on the report. XML 节点之一是我需要在报告中显示的“税”。 However, if another value exists in the XML dataset, I need to use get and display a different node's value for the Tax.但是,如果 XML 数据集中存在另一个值,我需要使用 get 并显示不同节点的 Tax 值。 Here is a minimized version of the XML datasource.这是 XML 数据源的最小化版本。

<Query>
 <XmlData><?xml version="1.0" encoding="us-ascii"?>
   <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CustomerName>Customer Name</CustomerName>
  <Invoices>
    <Invoice>
      <CustomerId>12345</CustomerId>
      <Tax>0.56</Tax>
      <parts>
        <part>
          <Category>Category1</Category>
          <Items>
            <Item>
              <ItemDescription>OtherItem1</ItemDescription>
              <ItemTotal>0.79</ItemTotal>
            </Item>
            <Item>
              <ItemDescription>NewSalesTax</ItemDescription>
              <ItemTotal>0.99</ItemTotal>
            </Item>
            <Item>
              <ItemDescription>OtherItem2</ItemDescription>
              <ItemTotal>0.59</ItemTotal>
            </Item>
          </Items>
        </part>
      </parts>
    </Invoice>
  </Invoices>
</Customer>

In the above XML, If "NewSalesTax" value exists for the ItemDescription node, I need to display the corresponding value of the ItemTotal node for the Tax value.在上面的 XML 中,如果 ItemDescription 节点存在“NewSalesTax”值,我需要为 Tax 值显示 ItemTotal 节点的相应值。 (ie 0.99) (即 0.99)

I can check if the node exists using the SUM function:我可以使用 SUM function 检查节点是否存在:

=SUM(iif(Fields!ItemDescription.Value="NewSalesTax",1,0))

But I am not sure how to target the corresponding ItemTotal value if it is found.但是我不确定如果找到相应的 ItemTotal 值如何定位。 Also note that I cannot rely on the Item being in a certain position within the Items Group.另请注意,我不能依赖项目组中某个 position 中的项目。 It can exist, not exist, be first, last or in the middle of the group.它可以存在,不存在,第一个,最后一个或在组的中间。

I haven't worked with an XML datasource, but if the Item Total works similarly to the Item Description field, the expression would be something like:我没有使用 XML 数据源,但如果 Item Total 与 Item Description 字段的工作方式类似,则表达式将类似于:

=SUM(IIF(Fields!ItemDescription.Value = "NewSalesTax", Fields!ItemTtotal.Value, CDEC(0)))

Which reads as the SUM of the Item Total if the Description is New Sales Tax.如果描述是新销售税,则显示为项目总计的总和。 The CDEC is used to convert the zero to a decimal to match the source type. CDEC 用于将零转换为十进制以匹配源类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM