0

这个问题是我上一个问题的后续。多亏了提供的答案,我才能够匹配谱系的查询项和查询名称。但是,我现在得到重复的查询项名称,因为在多个查询节点中使用了相同的项。

为了稍微解释一下 XML,dataItem“区域”位于多个查询中,XSL 正在遍历并将根/沿袭/项目/名称与 XML 中的查询/查询/选择/数据项/表达式匹配。但是,由于“区域”位于多个查询中,因此它会多次抓取它。我只想要一次。这是我正在使用的 XML 示例:

<root>
  <lineage>
    <item>
      <name>[Sales (query)].[Retailers].[Retailer Province-State]</name>
      <ns>[goretailers]</ns>
      <qs>[RETAILER_SITE]</qs>
      <qi>[Retailer Province-State]</qi>
    </item>
    <item>
      <name>[Sales (query)].[Products].[Product line]</name>
      <exp>#'[gosales].[PRODUCT_LINE].[PRODUCT_LINE_'+ $Language_lookup{$runLocale}+ '] '#</exp>
    </item>
  </lineage>

 <!--There is more XML code in between -->

<queries>
    <query name="RevenuMapquery">
    <!--More Code in between that is unimportant-->
    <selection>
        <dataItem name="Region">
            <expression>[AllRegion].[Region]</expression>
        </dataItem>
        <dataItem name="Revenue">
            <expression>[MeasureRevenue].[Revenue]</expression>
        </dataItem>
        <dataItem name="Planned revenue">
            <expression>[MeasureRevenue].[Planned revenue]</expression>
        </dataItem>
    </selection>
    </query>
    <query name="AllRegion">
    <source>
    <model />
    </source>
    <selection>
        <dataItem name="Region">
            <expression>[Sales (query)].[Retailers].[Retailer Province-State]</expression>
        </dataItem>
    </selection>
        <detailFilters>
        <detailFilter>
    <filterExpression>[Sales (query)].[Retailers].[Retailer country] = ('United States')    </filterExpression>
        </detailFilter>
        </detailFilters>
    </query>    
</root>
<xsl:key name="dataItems" match="dataItem" use="expression"/>

  <xsl:template match="root">
      <xsl:apply-templates select="lineage"/>
   </xsl:template>

<!-- The above is included at the top of the XSl stylesheet as a child of the stylesheet node -->

<xsl:for-each select="item">
   <Row>        
        <Cell Borders="#ffffff">
          <xsl:attribute name="Background">
            <xsl:choose>
              <xsl:when test="position() mod 2 = 1">#CCCCFF</xsl:when>
              <xsl:when test="position() mod 2 = 0">#FFFFFF</xsl:when>
            </xsl:choose>
          </xsl:attribute>
          <Paddings Left="5" Right="5" Top="2" Bottom="2"/>
          <xsl:for-each select="key('dataItems', name)">
              <Text Style="TableContent">
                  <xsl:value-of select="@name"/>
                      <xsl:apply-templates select="dataItems"/>
              </Text>
           </xsl:for-each>
        </Cell>    
   </Row>
</xsl:for-each>

我现在得到的结果类似于:Region, Region, Region, Product Line, Product Line, Revenue, Revenue

我想要的结果是:地区、产品线、收入

4

0 回答 0