Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:49+00:00 2026-05-28T21:31:49+00:00

Thanks in advance for your time. I have a deeply nested XML whose XSLT

  • 0

Thanks in advance for your time. I have a deeply nested XML whose XSLT 1.0 transformation I need to perform (for pdf generation). I’m pasting the XML partially and I apologize for it already!

I have re-tweaked the XML as below based off a couple of answers and I realized I bumped into more issues. Thank you for your patience.

Please let me know if any additional clarification is needed.

INPUT XML:

 <Reports>
  <Report>
    <ReportID>R123</ReportID>
    <ReportName>R123Name</ReportName>
    <PurchaseTypes>
      <PurchaseType>
        <Name>Purchase Type 2</Name>
        <Areas>
          <Area>
            <AreaType>American</AreaType>
            <AreaName>IL</AreaName>
            <SaleDetails>
              <SaleDetail>
                <SaleDetailID>
                  SD45
                </SaleDetailID>
                <Amount>
                  177.3
                </Amount>
              </SaleDetail>
              <SaleDetail>
                <SaleDetailID>
                  SD56
                </SaleDetailID>
                <Amount>
                  123
                </Amount>
              </SaleDetail>
            </SaleDetails>
          </Area>
          <Area>
            <AreaType>American</AreaType>
            <AreaName>MN</AreaName>
            <SaleDetails>
              <SaleDetail>
                <SaleDetailID>
                  SD19
                </SaleDetailID>
                <Amount>
                  19
                </Amount>
              </SaleDetail>

            </SaleDetails>
          </Area>
        </Areas>
      </PurchaseType>
    </PurchaseTypes>
  </Report>
</Reports>

Output needed similar to the image below

Sample Image 2:
https://picasaweb.google.com/lh/photo/hxTUY6Qv_9eJyvxQ-UhQutMTjNZETYmyPJy0liipFm0?feat=directlink

@DevNull, this is what I was trying:

  <xsl:template match="Report">
        <xsl:apply-templates select="ReportID|PurchaseTypes/PurchaseType"></xsl:apply-templates>
      </xsl:template>

 <xsl:template match="PurchaseType">
    <xsl:apply-templates select="Name|Areas/Area/AreaType"></xsl:apply-templates>
  </xsl:template>

But I’m seeing the area type American twice.
Something like this:
R123
Purchase Type 2
American
American

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:31:49+00:00Added an answer on May 28, 2026 at 9:31 pm

    Looking at your input XML and the excel image of the desired output, it still doesn’t look like you need grouping. The XML seems to already be organized the way you need your report(s) to be formatted.

    Here’s an example using XSL-FO to create the PDF.

    Your XML input:

    <Reports>
      <Report>
        <ReportID>R123</ReportID>
        <ReportName>R123Name</ReportName>
        <PurchaseTypes>
          <PurchaseType>
            <Name>Purchase Type 2</Name>
            <SaleDetails>
              <SaleDetail>
                <SaleDetailID>
                  SD45
                </SaleDetailID>
                <Amount>
                  177.3
                </Amount>
              </SaleDetail>
              <SaleDetail>
                <SaleDetailID>
                  SD56
                </SaleDetailID>
                <Amount>
                  123
                </Amount>
              </SaleDetail>
            </SaleDetails>
          </PurchaseType>
        </PurchaseTypes>
      </Report>
      <Report>
        <ReportID>R234</ReportID>
        <ReportName>R234Name</ReportName>
        <PurchaseTypes>
          <PurchaseType>
            <Name>Purchase Type 1</Name>
            <SaleDetails>
              <SaleDetail>
                <SaleDetailID>
                  SD456
                </SaleDetailID>
                <Amount>
                  17.3
                </Amount>
              </SaleDetail>
              <SaleDetail>
                <SaleDetailID>
                  SD556
                </SaleDetailID>
                <Amount>
                  23
                </Amount>
              </SaleDetail>
            </SaleDetails>
          </PurchaseType>
          <PurchaseType>
            <Name>Purchase Type 2</Name>
            <SaleDetails>
              <SaleDetail>
                <SaleDetailID>
                  SD451
                </SaleDetailID>
                <Amount>
                  12.2
                </Amount>
              </SaleDetail>
            </SaleDetails>
          </PurchaseType>
        </PurchaseTypes>
      </Report>
    </Reports>
    

    Transformed with this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="node()|@*">
        <xsl:apply-templates select="node()|@*"/>
      </xsl:template>
    
      <xsl:attribute-set name="reportBorder" use-attribute-sets="reportPadding">
        <xsl:attribute name="border">solid 1pt black</xsl:attribute>
      </xsl:attribute-set>
    
      <xsl:attribute-set name="reportPadding">
        <xsl:attribute name="padding-left">4pt</xsl:attribute>
        <xsl:attribute name="padding-right">4pt</xsl:attribute>
        <xsl:attribute name="padding-top">2pt</xsl:attribute>
        <xsl:attribute name="padding-bottom">2pt</xsl:attribute>    
      </xsl:attribute-set>
    
      <xsl:template match="Reports">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
          <fo:layout-master-set>
            <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
              <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
            </fo:simple-page-master>
          </fo:layout-master-set>
          <fo:page-sequence master-reference="my-page">
            <fo:flow flow-name="xsl-region-body">
              <xsl:apply-templates/>
            </fo:flow>
          </fo:page-sequence>
        </fo:root>
      </xsl:template>
    
      <xsl:template match="Report">
        <fo:table margin-bottom="12pt" border="solid 2pt black" width="2.5in">
          <fo:table-column column-number="1" width="1.5in"/>
          <fo:table-column column-number="2" width="1in"/>
          <fo:table-body>
            <xsl:apply-templates select="ReportID|PurchaseTypes/PurchaseType/Name"/>
          </fo:table-body>
        </fo:table>
      </xsl:template>
    
      <xsl:template match="ReportID">
        <fo:table-row>
          <fo:table-cell background-color="#FFFF00" border-top="solid 2pt black" border-left="solid 2pt black" xsl:use-attribute-sets="reportPadding">
            <fo:block><xsl:value-of select="."/></fo:block>
          </fo:table-cell>
          <fo:table-cell border-top="solid 2pt black" border-right="solid 2pt black">
            <fo:block>&#xA0;</fo:block>
          </fo:table-cell>
        </fo:table-row>    
      </xsl:template>
    
      <xsl:template match="Name">
        <xsl:if test="ancestor-or-self::PurchaseType[preceding-sibling::PurchaseType]">
          <fo:table-row border-left="solid 2pt black">
            <fo:table-cell>
              <fo:block>&#xA0;</fo:block>
            </fo:table-cell>
            <fo:table-cell>
              <fo:block>&#xA0;</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </xsl:if>
        <fo:table-row>
          <fo:table-cell background-color="#DDA0DD" border-left="solid 2pt black" xsl:use-attribute-sets="reportPadding">
            <fo:block><xsl:value-of select="normalize-space(.)"/></fo:block>
          </fo:table-cell>
          <fo:table-cell border-right="solid 2pt black">
            <fo:block>&#xA0;</fo:block>
          </fo:table-cell>
        </fo:table-row>    
        <fo:table-row background-color="#8FBC8F">
          <fo:table-cell xsl:use-attribute-sets="reportBorder">
            <fo:block>Sale Detail ID</fo:block>
          </fo:table-cell>
          <fo:table-cell xsl:use-attribute-sets="reportBorder">
            <fo:block>Amount</fo:block>
          </fo:table-cell>
        </fo:table-row>
        <xsl:apply-templates select="following-sibling::SaleDetails/SaleDetail"/>
      </xsl:template>
    
      <xsl:template match="SaleDetail">
        <fo:table-row>
          <fo:table-cell xsl:use-attribute-sets="reportBorder">
            <fo:block><xsl:value-of select="normalize-space(SaleDetailID)"/></fo:block>
          </fo:table-cell>
          <fo:table-cell xsl:use-attribute-sets="reportBorder" text-align="right">
            <fo:block><xsl:value-of select="normalize-space(Amount)"/></fo:block>
          </fo:table-cell>
        </fo:table-row>    
      </xsl:template>
    </xsl:stylesheet>
    

    Produces this PDF:

    enter image description here

    Hopefully what’s happening isn’t lost in the FO markup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

and thanks in advance for your time. We are using CSLA 3.5.1, although, ultimately,
First time asking a question here so thanks in advance for your time. I
thanks in advance for your help. I am wondering if there is a (design)
Thanks in advance for your help experts. I want to be able to copy
First hi and thanks in advance in ASP.NET : assume that i have a
I am using c# .net. Thanks in advance for any help. I have searched
Thanks in Advance for reading and answer this question. I got button in asp
Special thanks in advance for sending me answer........ I m the beginner in iphone
Hello (and thanks in advance) I'm in a bit of a quandry, I cant
First of all thanks in advance, this has been very frustrating and I'm hoping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.