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 7166523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:25:39+00:00 2026-05-28T14:25:39+00:00

I have an xml like below: <?xml version=1.0 encoding=utf-8?> <GetSavedReportResponse> <ResponseType>Success</ResponseType> <FileModifiedDateTime>2012-01-03T17:05:04</FileModifiedDateTime> <FileSizeBytes>7816</FileSizeBytes> <FileDataFormat>XML</FileDataFormat>

  • 0

I have an xml like below:

<?xml version="1.0" encoding="utf-8"?>
  <GetSavedReportResponse>
  <ResponseType>Success</ResponseType>
  <FileModifiedDateTime>2012-01-03T17:05:04</FileModifiedDateTime>
  <FileSizeBytes>7816</FileSizeBytes>
  <FileDataFormat>XML</FileDataFormat>
  <FileData>
    <Zthes>
      <term>
        <termId>49555</termId>
        <termUpdate>add</termUpdate>
        <termName>Active Personnel</termName>
        <termVocabulary>People Status Global</termVocabulary>
        <termVocabulary>Global People Status</termVocabulary>
        <termCategory>PDA</termCategory>
        <termCategory>PDI</termCategory>
        <termCategory>GLB</termCategory>
        <relation weight="100">
          <termId>49556</termId>
          <relationType>EQ</relationType>
          <termName>term name</termName>
          <termVocabulary>term vocabulary</termVocabulary>
        </relation>
        <relation weight="100">
          <termId>49557</termId>
          <relationType>BT</relationType>
          <termName>General Active Personnel</termName>
          <termVocabulary>People Status Global Updated</termVocabulary>
        </relation>
      </term>
      <term>
        <termId>49556</termId>
        <termUpdate>add</termUpdate>
        <termName>Leave of Absence Personnel</termName>
        <termVocabulary>People Status Global</termVocabulary>
        <termCategory>GLB</termCategory>
        <termCategory>PDI</termCategory>
        <relation weight="100">
          <relationType>BT</relationType>
          <termId>49554</termId>
          <termName>General Non-Active Personnel</termName>
          <termVocabulary>People Status Global</termVocabulary>
        </relation>
      </term>
    </Zthes>
  </FileData>
</GetSavedReportResponse>

I need to transform it into a flat file. For that, I have writen the following xsl

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" />
  <xsl:template match="Zthes">
    <xsl:text>&#10;</xsl:text>
    <xsl:for-each select="term">
      <xsl:text>"</xsl:text>
      <xsl:text>GL</xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:text>;</xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:for-each select="termCategory">
        <xsl:value-of select="." />
      </xsl:for-each>
      <xsl:text>"</xsl:text>
      <xsl:text>;</xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:for-each select="termVocabulary">
        <xsl:value-of select="." />
      </xsl:for-each>
      <xsl:text>"</xsl:text>
      <xsl:text>;</xsl:text>
      <xsl:text>"</xsl:text>
      <xsl:for-each select="relation/termVocabulary">
          <xsl:value-of select="." />
      </xsl:for-each>
      <xsl:text>"</xsl:text>
      <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

so, the output should be

“HDR”;”Text”;”20120112045620″;”F”
“GL”;”PDA”;”People Status Global”;”term vocabulary”
“GL”;”PDA”;”People Status Global”;”People Status Global Updated”
“GL”;”PDA”;”Global People Status”;”term vocabulary”
“GL”;”PDA”;”Global People Status”;”People Status Global Updated”
“GL”;”PDI”;”People Status Global”;”term vocabulary”
“GL”;”PDI”;”People Status Global”;”People Status Global Updated”
“GL”;”PDI”;”Global People Status”;”term vocabulary”
“GL”;”PDI”;”Global People Status”;”People Status Global Updated”
“GL”;”GLB”;”People Status Global”;”term vocabulary”
“GL”;”GLB”;”People Status Global”;”People Status Global Updated”
“GL”;”GLB”;”Global People Status”;”term vocabulary”
“GL”;”GLB”;”Global People Status”;”People Status Global Updated”
“FTR”;12

with my xsl I am gettin single row:
“GL”;”PDAPDIGLB”;”People Status GlobalGlobal People Status”;”term vocabularyPeople Status Global Updated”

And a header row :
“HDR”;”PIGLSSTD”;”20120112045620″;”F”:
should be appended at the start, along with a footer row
“FTR”;

at the bottom.

  • 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-28T14:25:40+00:00Added an answer on May 28, 2026 at 2:25 pm

    You want something like this:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <my:defaults>
       <termCat/>
       <termVocab/>
     </my:defaults>
    
     <xsl:variable name="vDefaults" select="document('')/*/my:defaults"/>
    
     <xsl:variable name="vQ">"</xsl:variable>
    
     <xsl:template match="term">
       <xsl:variable name="vTerm" select="."/>
    
       <xsl:variable name="vRow1" select="'&#xA;&quot;GL&quot;;'"/>
    
         <xsl:for-each select=
          "termCategory
          |
           $vDefaults/termCat[not($vTerm/termCategory)]">
           <xsl:variable name="vRow2" select=
               "concat($vRow1, $vQ, ., $vQ, ';')"/>
    
           <xsl:for-each select=
            "$vTerm/termVocabulary
            |
             $vDefaults/termCat[not($vTerm/termVocabulary)]
            ">
             <xsl:variable name="vRow3" select=
               "concat($vRow2, $vQ, ., $vQ, ';')"/>
    
            <xsl:for-each select=
             "$vTerm/relation/termVocabulary
             |
              $vDefaults/termCat[not($vTerm/relation/termVocabulary)]
             ">
            <xsl:value-of select="concat($vRow3, $vQ, ., $vQ, ';')"/>
          </xsl:for-each>
          </xsl:for-each>
         </xsl:for-each>
     </xsl:template>
    
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <GetSavedReportResponse>
        <ResponseType>Success</ResponseType>
        <FileModifiedDateTime>2012-01-03T17:05:04</FileModifiedDateTime>
        <FileSizeBytes>7816</FileSizeBytes>
        <FileDataFormat>XML</FileDataFormat>
        <FileData>
            <Zthes>
                <term>
                    <termId>49555</termId>
                    <termUpdate>add</termUpdate>
                    <termName>Active Personnel</termName>
                    <termVocabulary>People Status Global</termVocabulary>
                    <termVocabulary>Global People Status</termVocabulary>
                    <termCategory>PDA</termCategory>
                    <termCategory>PDI</termCategory>
                    <termCategory>GLB</termCategory>
                    <relation weight="100">
                        <termId>49556</termId>
                        <relationType>EQ</relationType>
                        <termName>term name</termName>
                        <termVocabulary>term vocabulary</termVocabulary>
                    </relation>
                    <relation weight="100">
                        <termId>49557</termId>
                        <relationType>BT</relationType>
                        <termName>General Active Personnel</termName>
                        <termVocabulary>People Status Global Updated</termVocabulary>
                    </relation>
                </term>
                <term>
                    <termId>49556</termId>
                    <termUpdate>add</termUpdate>
                    <termName>Leave of Absence Personnel</termName>
                    <termVocabulary>People Status Global</termVocabulary>
                    <termCategory>GLB</termCategory>
                    <termCategory>PDI</termCategory>
                    <relation weight="100">
                        <relationType>BT</relationType>
                        <termId>49554</termId>
                        <termName>General Non-Active Personnel</termName>
                        <termVocabulary>People Status Global</termVocabulary>
                    </relation>
                </term>
            </Zthes>
        </FileData>
    </GetSavedReportResponse>
    

    the wanted, correct result is produced:

    "GL";"PDA";"People Status Global";"term vocabulary";
    "GL";"PDA";"People Status Global";"People Status Global Updated";
    "GL";"PDA";"Global People Status";"term vocabulary";
    "GL";"PDA";"Global People Status";"People Status Global Updated";
    "GL";"PDI";"People Status Global";"term vocabulary";
    "GL";"PDI";"People Status Global";"People Status Global Updated";
    "GL";"PDI";"Global People Status";"term vocabulary";
    "GL";"PDI";"Global People Status";"People Status Global Updated";
    "GL";"GLB";"People Status Global";"term vocabulary";
    "GL";"GLB";"People Status Global";"People Status Global Updated";
    "GL";"GLB";"Global People Status";"term vocabulary";
    "GL";"GLB";"Global People Status";"People Status Global Updated";
    "GL";"GLB";"People Status Global";"People Status Global";
    "GL";"PDI";"People Status Global";"People Status Global";
    

    Explanation: You want to do output only when a complete line has been formed — not before that.

    Update: The OP works in an environment, where the document() function is disabled. He also wants a header and a footer.

    In this case a slightly modified transformation can be used (using the exslt:node-set() extension function) now:

    <xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:ext="http://exslt.org/common">
         <xsl:output omit-xml-declaration="yes" indent="yes"/>
         <xsl:strip-space elements="*"/>
    
         <xsl:variable name="vrtfDefaults">
           <termCat/>
           <termVocab/>
         </xsl:variable>
    
         <xsl:variable name="vDefaults" select=
          "ext:node-set($vrtfDefaults)"/>
    
         <xsl:variable name="vQ">"</xsl:variable>
    
         <xsl:template match="Zthes">
          <xsl:text>HDR";"PIGLSSTD";"20120112045620";"F":</xsl:text>
    
            <xsl:apply-templates/>
    
          <xsl:text>&#xA;FTR</xsl:text>
         </xsl:template>
    
         <xsl:template match="term">
           <xsl:variable name="vTerm" select="."/>
    
           <xsl:variable name="vRow1" select="'&#xA;&quot;GL&quot;;'"/>
    
             <xsl:for-each select=
              "termCategory
              |
               $vDefaults/termCat[not($vTerm/termCategory)]">
               <xsl:variable name="vRow2" select=
                   "concat($vRow1, $vQ, ., $vQ, ';')"/>
    
               <xsl:for-each select=
                "$vTerm/termVocabulary
                |
                 $vDefaults/termCat[not($vTerm/termVocabulary)]
                ">
                 <xsl:variable name="vRow3" select=
                   "concat($vRow2, $vQ, ., $vQ, ';')"/>
    
                <xsl:for-each select=
                 "$vTerm/relation/termVocabulary
                 |
                  $vDefaults/termCat[not($vTerm/relation/termVocabulary)]
                 ">
                <xsl:value-of select="concat($vRow3, $vQ, ., $vQ, ';')"/>
              </xsl:for-each>
              </xsl:for-each>
             </xsl:for-each>
         </xsl:template>
    
         <xsl:template match="text()"/>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml code that looks like below: <?xml version=1.0 encoding=UTF-8?> <metadata><fields><field-order/></fields><roles><role name=DEFAULT3_MOD><state
I have created a module in Flex like below: modules/ModuleBase.mxml <?xml version=1.0 encoding=utf-8?> <mx:Module
I have a XML Like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body>
I have a XML like this: <?xml version=1.0 encoding=UTF-8?> <nodes> <n c=value2/> <n>Has a
I have XML shaped like the following: <?xml version=1.0 encoding=UTF-8?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http://a9.com/-/spec/opensearch/1.1/ xmlns:docs=http://schemas.google.com/docs/2007
I have an XML (first.xml) which looks like :: <?xml version=1.0 encoding=utf-8?> <saw:jobInfo xmlns:saw=com.analytics.web/report/v1.1>
I need to parse an XML like this: <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <pictures> <pic>
HI Can i have a xml defination like below <add key=FirstName ServerType=FirstName Mandatory=Yes length=3
I have an XML file which has many section like the one below: <Operations>
I have a simple layout like below (which only shows a text TEST): <?xml

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.