0
votes

Given the input XML data:

<Report_Entry>
    <Time_Off_Type_Group>
        <Time_Off_Type Descriptor="Sickness Full" />
    </Time_Off_Type_Group>
    <Time_Off_Type_Group>
        <Time_Off_Type Descriptor="Sickness Part" />
    </Time_Off_Type_Group>
    <Time_Off_Entry_ID>2d90199913fa9fae8</Time_Off_Entry_ID>
    <Request_or_Correction>Time Off Request</Request_or_Correction>
</Report_Entry>

As a result, I expect the output data via the condition: "for-each Time_Off_Type_Group move Time_Off_Entry_ID and Request_or_Correction into the Time_Off_Type_Group"

Output example:

<Report_Entry>
    <Time_Off_Type_Group>
        <Time_Off_Type Descriptor="Sickness Full" />
        <Time_Off_Entry_ID>2d90199913fa9fae8</Time_Off_Entry_ID>
        <Request_or_Correction>Time Off Request</Request_or_Correction>
    </Time_Off_Type_Group>
    <Time_Off_Type_Group>
        <Time_Off_Type Descriptor="Sickness Part" />
        <Time_Off_Entry_ID>2d90199913fa9fae8</Time_Off_Entry_ID>
        <Request_or_Correction>Time Off Request</Request_or_Correction>
    </Time_Off_Type_Group>
</Report_Entry>
2
Please ask a specific question about a difficulty you encountered when trying to accomplish this. Otherwise it looks like you're just looking for someone to do your work for you.michael.hor257k
Sorry, you are right. I forgot to attach my version of solving it. Under your comments, I posted the my initial version of XSLYuriy Martynyuk

2 Answers

0
votes

Think templates not for-each, so write a template for the Time_Off_Type_Group elements copying the siblings as children and make sure the default idendity copying does not apply to those siblings:

<?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="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Time_Off_Type_Group">
      <xsl:copy>
          <xsl:copy-of select="*, ../(* except Time_Off_Type_Group)"/>
      </xsl:copy>
  </xsl:template>

  <xsl:template match="Report_Entry/*[not(self::Time_Off_Type_Group)]"/>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/bEzkTcn

0
votes

Or shortly:

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

<xsl:template match="/Report_Entry">
    <xsl:variable name="common" select="Time_Off_Entry_ID | Request_or_Correction" />
    <xsl:copy>
        <xsl:for-each select="Time_Off_Type_Group">
            <xsl:copy>
                <xsl:copy-of select="* | $common"/>
            </xsl:copy>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>