muenchian grouping in the second level

后端 未结 2 1858
闹比i
闹比i 2021-01-21 14:58

This is my xml input


  
    
      6.14.0
            


        
相关标签:
2条回答
  • 2021-01-21 15:06

    I think you have to make your key more specific. When defining a key in XSLT it is always defined for the whole XML document, not for sections. You have to concat() more than one value when defining a key.

    Plesae have a look at this thread: Muenchian Grouping - group within a node, not within the entire document

    Best regards, Peter

    0 讨论(0)
  • 2021-01-21 15:27

    This transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output omit-xml-declaration="yes" indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:key name="versions" match="fix_version" use="."/>
      <xsl:key name="type" match="@type" use="../*/fix_version"/>
    
      <xsl:template match="fix_version[generate-id()=generate-id(key('versions',.)[1])]">
         <div class="version">
         <a><xsl:value-of select="."/></a>
           <div class="issues">
             <xsl:for-each select="key('type',.)">
               <div class="{.}">
                 <a href="{../title}"><xsl:value-of select="../title"/></a>
               </div>
             </xsl:for-each>
           </div>
         </div>
       </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <issues>
      <issue status="open" type="Bug">
        <fix_versions>
          <fix_version>6.14.0</fix_version>
          <fix_version>6.13.0</fix_version>
          <fix_version>6.12.0</fix_version>
        </fix_versions>
        <title>issue1</title>
        <description>Description</description>
      </issue>
      <issue status="open" type="Feature">
        <fix_versions>
          <fix_version>6.13.0</fix_version>
        </fix_versions>
        <title>issue2</title>
        <description>Description</description>
      </issue>
      <issue status="open" type="Improvement">
        <fix_versions>
          <fix_version>6.14.0</fix_version>
        </fix_versions>
        <title>issue3</title>
        <description>Description</description>
      </issue>
      ...
    </issues>
    

    produces the wanted, correct result:

    <div class="version">
       <a>6.14.0</a>
       <div class="issues">
          <div class="Bug">
             <a href="issue1">issue1</a>
          </div>
          <div class="Improvement">
             <a href="issue3">issue3</a>
          </div>
       </div>
    </div>
    <div class="version">
       <a>6.13.0</a>
       <div class="issues">
          <div class="Bug">
             <a href="issue1">issue1</a>
          </div>
          <div class="Feature">
             <a href="issue2">issue2</a>
          </div>
       </div>
    </div>
    <div class="version">
       <a>6.12.0</a>
       <div class="issues">
          <div class="Bug">
             <a href="issue1">issue1</a>
          </div>
       </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题