如何正确使用 Muenchian 按元素对非常重复的标签进行分组?

Posted

技术标签:

【中文标题】如何正确使用 Muenchian 按元素对非常重复的标签进行分组?【英文标题】:How to properly use the Muenchian for grouping a very repetitive tag by an element? 【发布时间】:2017-12-21 03:21:09 【问题描述】:

我在使用 Muenchian 时遇到问题。我有一个非常大的 xml 可以转换为新的输出。我已经构建了 xsl 以使用一个元素作为“父级”进行分组,并将所有内容作为子级返回。来源对于不同的孩子有很多次相同的父母,但它只带来第一个。

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Calculate_Account_Level_S6>

<Account_Number_ANI_ID17>7700.401100.900</Account_Number_ANI_ID17>
 <Description001_ID19>A/P ThirdParty</Description001_ID19>
 <Parent_Account_Number_ANI_ID21>401100.900</Parent_Account_Number_ANI_ID21>
 <DebitCreditAccount_ID26>A</DebitCreditAccount_ID26>
 <Account_Group_Gen_ID28>MX2010101</Account_Group_Gen_ID28>
</Calculate_Account_Level_S6>

<Calculate_Account_Level_S6>
 <Account_Number_ANI_ID17>7700100.401100.900</Account_Number_ANI_ID17>
 <Description001_ID19>A/P ThirdParty</Description001_ID19>
 <Parent_Account_Number_ANI_ID21>401100.900</Parent_Account_Number_ANI_ID21>
 <DebitCreditAccount_ID26>A</DebitCreditAccount_ID26>
 <Account_Group_Gen_ID28>MX2010101</Account_Group_Gen_ID28>
</Calculate_Account_Level_S6>
 <Calculate_Account_Level_S6>
 <Account_Number_ANI_ID17>7700101.401100.900</Account_Number_ANI_ID17>
 <Description001_ID19>A/P ThirdParty</Description001_ID19>
 <Parent_Account_Number_ANI_ID21>401100.900</Parent_Account_Number_ANI_ID21>
 <DebitCreditAccount_ID26>A</DebitCreditAccount_ID26>
 <Account_Group_Gen_ID28>MX2010101</Account_Group_Gen_ID28>
</Calculate_Account_Level_S6>

 XSL KEY:
 <xsl:key name="GrpParentAccount" match="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6" use="Parent_Account_Number_ANI_ID21" />
 <xsl:key name="Account" match="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6" use="Account_Number_ANI_ID17" />
 Coding:
   <xsl:for-each select="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6[count(. | key('GrpParentAccount', Parent_Account_Number_ANI_ID21)[1]) = 1]">
    <xsl:sort select="Parent_Account_Number_ANI_ID21"/>
    <xsl:sort select="Account_Number_ANI_ID17"/>
      <catalogocuentas:Ctas>
        <xsl:attribute name="CodAgrup">
          <xsl:value-of select="substring(Account_Group_Gen_ID28,3.0,3.0)"/>
        </xsl:attribute>
        <xsl:attribute name="NumCta">
          <xsl:value-of select="Parent_Account_Number_ANI_ID21"/>
        </xsl:attribute>
        <xsl:attribute name="Desc">
          <xsl:value-of select="Converted_Account_Description_ID29"/>
        </xsl:attribute>
          <xsl:attribute name="SubCtaDe">
            <xsl:text disable-output-escaping="no"></xsl:text>
          </xsl:attribute>
        <xsl:attribute name="Nivel">
          <xsl:text disable-output-escaping="no">1</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="Natur">
          <xsl:value-of select="DebitCreditAccount_ID26"/>
        </xsl:attribute>
      </catalogocuentas:Ctas>
    <!-- Grouping End -->

       <!-- Printing All Accounts by Group -->
       <xsl:for-each select="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6[count(. | key('Account', Account_Number_ANI_ID17)[1]) = 1]">-->
        <catalogocuentas:Ctas>
         <xsl:attribute name="CodAgrup">
           <xsl:value-of select="substring(Account_Group_Gen_ID28,3.0,5.0)"/>
         </xsl:attribute>
        <xsl:attribute name="NumCta">
          <xsl:value-of select="Account_Number_ANI_ID17"/>
        </xsl:attribute>
        <xsl:attribute name="Desc">
          <xsl:value-of select="Converted_Account_Description_ID29"/>
        </xsl:attribute>
        <xsl:if test='Parent_Account_Number_ANI_ID21 != ""'>
          <xsl:attribute name="SubCtaDe">
            <xsl:value-of select="Parent_Account_Number_ANI_ID21"/>
          </xsl:attribute>
        </xsl:if>
        <xsl:attribute name="Nivel">
          <xsl:text disable-output-escaping="no">2</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="Natur">
          <xsl:value-of select="DebitCreditAccount_ID26"/>
        </xsl:attribute>
      </catalogocuentas:Ctas>
  </xsl:for-each>
  </xsl:for-each>
</catalogocuentas:Catalogo>
<catalogocuentas:Ctas CodAgrup="201" NumCta="401100.900" Desc="Proveedores IVA 16%" SubCtaDe="" Nivel="1" Natur="A"/><catalogocuentas:Ctas CodAgrup="20101" NumCta="7700.401100.900" Desc="Proveedores IVA 16%" SubCtaDe="401100.900" Nivel="2" Natur="A"/></catalogocuentas:Catalogo>
 I was expecting to print all Calculate_Account_Level_S6/Account_Number_ANI_ID17 by the Calculate_Account_Level_S6/Parent_Account_Number_ANI_ID21 Any help is very WELCOME !!! :)

【问题讨论】:

【参考方案1】:

尝试从

更改第二个键
<xsl:key name="Account" match="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6" use="Account_Number_ANI_ID17" />

<xsl:key name="Account" match="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6" use="concat(Account_Number_ANI_ID17, '|', Account_Number_ANI_ID17)" />

以及来自

的内部for-each
<xsl:for-each select="/RLA70901/Generic_Char_of_Account_Generation_S5/Calculate_Account_Level_S6[count(. | key('Account', Account_Number_ANI_ID17)[1]) = 1]">

<xsl:for-each select="key('GrpParentAccount', Parent_Account_Number_ANI_ID21)[count(. | key('Account', concat(Account_Number_ANI_ID17, '|', Account_Number_ANI_ID17))[1]) = 1]">

【讨论】:

太棒了!!!它确实工作得很好!非常感谢人!终于可以出去度假了!

以上是关于如何正确使用 Muenchian 按元素对非常重复的标签进行分组?的主要内容,如果未能解决你的问题,请参考以下文章

将 Muenchian 分组应用于 XSLT

如何使用 Muenchian 分组 XSLT 1.0 在每个目录中按标题分组

Muenchian 分组样式表返回重复的未分组节点

xsl muenchian 分组多个级别

Muenchian分组中的[1]真的有必要吗?

我无法理解 XSLT 1.0 Muenchian 分组