0
votes

I have an xml with the following structure:

<FlightDetails>
                        <CouponNumber>1</CouponNumber>
                        <ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
                        <CouponNumber>2</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
                        <CouponNumber>3</CouponNumber>
                        <ServiceClass>Y</ServiceClass>
</FlightDetails>

The xslt used is :

<FlightDetails>
          <xsl:for-each select="FlightDetails/CouponNumber">
          <CouponNumber>
          <xsl:value-of select="." />
          </CouponNumber>
          </xsl:for-each>
          <xsl:for-each select="FlightDetails/ServiceClass">
          <ServiceClass>
          <xsl:value-of select="." />
          </ServiceClass>
          </xsl:for-each>
</FlightDetails>

The transformation of the xml to an output xml using the xslt shows:

<FlightDetails>
<CouponNumber>1</CouponNumber>
<CouponNumber>2</CouponNumber>
<CouponNumber>3</CouponNumber>
<ServiceClass>Y</ServiceClass>
<ServiceClass>Y</ServiceClass>
<ServiceClass>Y</ServiceClass>
</FlightDetails>

However, the required output xml should look like:

<FlightDetails>
    <CouponNumber>1</CouponNumber>
    <ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
    <CouponNumber>2</CouponNumber>
    <ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
    <CouponNumber>3</CouponNumber>
    <ServiceClass>Y</ServiceClass>
</FlightDetails>

How to modify the XSLT to achieve the above output xml structure?

1
Your output should be identical to your input? That would mnake for a very trivial xslt... <xsl:template match="/"><xsl:copy-of select="*></xs;</template>, but is that what you want?oerkelens
Your input and output are exactly the same - where is the transformation you want to happen?Tomalak
Thanks all for the valuable inputs. The transformation is required for other parts of the xml. It's correct that this particular part of the xml undergoes no transformation and the suggestions worked for me. Thanks a zillion!user2967948

1 Answers

0
votes

You could try,

XSL:

 <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
       <xsl:output indent="yes" />

    <xsl:template match="/">
         <xsl:copy-of select="//FlightDetails"/>
    </xsl:template>
    </xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<FlightDetails>
      <CouponNumber>1</CouponNumber>
      <ServiceClass>Y</ServiceClass>
   </FlightDetails>
<FlightDetails>
      <CouponNumber>2</CouponNumber>
      <ServiceClass>Y</ServiceClass>
   </FlightDetails>
<FlightDetails>
      <CouponNumber>3</CouponNumber>
      <ServiceClass>Y</ServiceClass>
   </FlightDetails>