-3

I am preparing one flat file from XMl using XSLT 2.0. My input XML is

<city>
  <family>
    <parent>A</parent>
    <child>A1</child>
  </family>
  <family>
    <parent>A</parent>
    <child>A2</child>
  </family>
  <family>
    <parent>B</parent>
    <child>B1</child>
  </family>
  <family>
    <parent>B</parent>
    <child>B2</child>
  </family>
  <family>
    <parent>B</parent>
    <child>B3</child>
  </family>
  <family>
    <parent>C</parent>
    <child>C1</child>
  </family>


 </city>

Expected Output
-----------------
01 A 
02 B
03 C

I have to group parent and each parent has one entry in flat file and it should have correct sequence no. I am not able to generate sequence no correcly.

Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148
Gnana
  • 2,130
  • 5
  • 26
  • 57

1 Answers1

2

Assuming you use for-each-group then outputting and formatting the position() should suffice:

  <xsl:template match="/">
      <xsl:for-each-group select="city/family" group-by="parent">
          <xsl:value-of select="concat(format-number(position(), '00'), ' ', current-grouping-key(), '&#10;')"/>
      </xsl:for-each-group>
  </xsl:template>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110