-1

I am using this algo

http://www.jenitennison.com/xslt/grouping/muenchian.html for grouping . I am able to use that algo .but I am facing one issue .I have one xml in which i apply grouping on Over .I am able to show my data .but sometime @over become blank ..I don't want to show that data .. here is my code http://xsltransform.net/pNmBxZY/1

transformation

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
   <xsl:key name="node-by-over" match="Node" use="@Over" />

    <xsl:template match="/Innings">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
        <xsl:apply-templates select="Node[generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>

      </hmtl>
    </xsl:template>

     <xsl:template match="Node">
   over::: <h1><xsl:value-of select="@Over"/></h1>
    <table id="{Over}">

      <xsl:for-each select="key('node-by-over', @Over)">
        <tr>
         <td>balls:::<xsl:value-of select="@Ball"/></td>
        <td>runs:::<xsl:value-of select="Runs"/></td>

         </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:transform>

current result

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<hmtl>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>New Version!</title>
   </head>
   over::: 
   <h1>1</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::6</td>
         <td>runs:::2</td>
      </tr>
   </table>
   over::: 
   <h1></h1>
   <table id="">
      <tr>
         <td>balls:::</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::</td>
         <td>runs:::0</td>
      </tr>
   </table>
   over::: 
   <h1>2</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::2</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::6</td>
         <td>runs:::1</td>
      </tr>
   </table>
   over::: 
   <h1>3</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::1</td>
      </tr>
   </table>
</hmtl>

Expected output

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<hmtl>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>New Version!</title>
   </head>
   over::: 
   <h1>1</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::6</td>
         <td>runs:::2</td>
      </tr>
   </table>

   over::: 
   <h1>2</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::2</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::6</td>
         <td>runs:::1</td>
      </tr>
   </table>
   over::: 
   <h1>3</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::1</td>
      </tr>
   </table>
</hmtl>

Difference between current and expected output

over::: 
   <h1></h1>
   <table id="">
      <tr>
         <td>balls:::</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::</td>
         <td>runs:::0</td>
      </tr>
   </table>

I don't want traverse that Node which have blank @Over ..See example in xml

 <Node Id="14" Over="" 

I don't want to traverse id="14" because it don't have over value .but current code is doing that why it show above html part ? how to apply check ?

currently last node display like that

over::: 
   <h1>3</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::1</td>
      </tr>
   </table>

Can we show like that

over::: 
   <h1>2.5</h1>
   <table id="">
      <tr>
         <td>balls:::1</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::2</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::3</td>
         <td>runs:::1</td>
      </tr>
      <tr>
         <td>balls:::4</td>
         <td>runs:::0</td>
      </tr>
      <tr>
         <td>balls:::5</td>
         <td>runs:::1</td>
      </tr>
   </table>

@over.@ball (Last node)

user944513
  • 12,247
  • 49
  • 168
  • 318

1 Answers1

1

If I understand this correctly, you want to change:

<xsl:apply-templates select="Node[generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>

to:

<xsl:apply-templates select="Node[@Over>0][generate-id() = generate-id(key('node-by-over', @Over)[1])]"/>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • that is correct `` '..thanks for help – user944513 May 31 '17 at 17:27
  • one more thing I want to ask ..can I show last `Node` or `over` with previous over followed by balls – user944513 May 31 '17 at 17:27
  • I am afraid I don't understand what you mean. AFAICT, you have changed 3 to 2.5, but I don't know why. – michael.hor257k May 31 '17 at 17:34
  • yes I have changed 3 to 2.5 (last node) .what ever be last node .it will come like @over.@ball – user944513 May 31 '17 at 17:36
  • why ? because there is rule in `cricket` .Each over has 6 balls .if it completed than I need to show like 1,2,3 .if it is not completed than I need to show over +ball..so in my example 3 over is not completed so I need to show like 2.5 ..it mean blower will bowl one more bowl or delivery – user944513 May 31 '17 at 17:38
  • 1
    Why are you making this so difficult? I don't know anything about cricket. I do know a little bit about logic. And I don't see any combination of `over` (with the value of 3) and `ball` (with values going from 1 to 5) that would produce 2.5. – michael.hor257k May 31 '17 at 17:44
  • sorry don't take me wrong ..Actually in `grouping` we break our code into parts like all @over 1 ,2,3 ..correct .from this 1
    – user944513 May 31 '17 at 17:47
  • From id="26" we found that my last over is 3 ..can we subtract 1..so if last is 3 .if subtract 1 it become 2. add @ball – user944513 May 31 '17 at 17:51
  • 1
    I am afraid this is clear as mud and the time I am willing to spend here has run out. Good luck! – michael.hor257k May 31 '17 at 17:53