0
votes

I have data as my Input XML as below:

<Travelers>
<Surname>GROUPNAME</Surname><PNRNameNumber>1</PNRNameNumber><PassengerNumber>1</PassengerNumber>
<TravelerSegments>
    <SegmentNumber>1</SegmentNumber>
    <SeatLegRecords>
        <SeatBoardPoint>ORD</SeatBoardPoint>
        <SeatOffPoint>SFO</SeatOffPoint>
        <SeatNumbers>30A</SeatNumbers>
        <SeatNumbers>30B</SeatNumbers>
        <SeatNumbers>30C</SeatNumbers>
        <SeatNumbers>30D</SeatNumbers>
        <SeatNumbers>30E</SeatNumbers>
        <SeatNumbers>30F</SeatNumbers>
        <SeatNumbers>30G</SeatNumbers>
        <SeatNumbers>30H</SeatNumbers>
        <SeatNumbers>31A</SeatNumbers>
    </SeatLegRecords>
    <SeatLegRecords>
        <SeatBoardPoint>SFO</SeatBoardPoint>
        <SeatOffPoint>LAX</SeatOffPoint>
        <SeatNumbers>30A</SeatNumbers>
        <SeatNumbers>30B</SeatNumbers>
        <SeatNumbers>30C</SeatNumbers>
        <SeatNumbers>30D</SeatNumbers>
        <SeatNumbers>30E</SeatNumbers>
        <SeatNumbers>30F</SeatNumbers>
        <SeatNumbers>30G</SeatNumbers>
        <SeatNumbers>30H</SeatNumbers>
        <SeatNumbers>31A</SeatNumbers>
    </SeatLegRecords>
</TravelerSegments>

And I want my output to display such as -

    {
    [ "30A","30B",30C","30D","30E","30F","30G","30H","31A"],
    [ "30A","30B",30C","30D","30E","30F","30G","30H","31A"]
    }

Can some one help me with XSLT 1.0 ? I know it is easy in XSLT 2.0 . But, i do not have XLST 2.0 available in my environment.

1
I don't see any grouping here. How would you do this in XSLT 2.0?michael.hor257k
using for-each-groupbySmitha
Group by what? As I said, I see no grouping here. Clarify your question.michael.hor257k

1 Answers

0
votes
 Try this.

  <xsl:template match="TravelerSegments">
    <xsl:value-of select="'{&#13;'"/>
    <xsl:apply-templates select=".//SeatLegRecords"/>
    <xsl:value-of select="'&#13;}'"/>
  </xsl:template>

  <xsl:template match="SeatLegRecords">
    <xsl:if test="position() &gt; 1">
      <xsl:value-of select="',&#13;'"/>
    </xsl:if>
    <xsl:value-of select="'['"/>
    <xsl:apply-templates select=".//SeatNumbers"/>
    <xsl:value-of select="']'"/>
  </xsl:template>

  <xsl:template match="SeatNumbers">
    <xsl:if test="position() &gt; 1">
      <xsl:value-of select="','"/>
    </xsl:if>
    <xsl:value-of select="concat('&quot;',.,'&quot;')"/>
  </xsl:template>

  <xsl:template match="node()">
    <xsl:apply-templates select="node()"/>
  </xsl:template>