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

  • Home
  • SEARCH
  • 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 8461977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:02:03+00:00 2026-06-10T14:02:03+00:00

I want to transfor hierarchical elements that represent a tree. The data is provided

  • 0

I want to transfor hierarchical elements that represent a tree. The data is provided inside a table in this format:

<?xml version="1.0" encoding="utf-16"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
    <asx:values>
        <CONCEPTS>
            <item>
                <NO>1</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.monetary</XBRL_ID>
                <IS_TUPLE>false</IS_TUPLE>
                <FATHER_ID/>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF>EUR</UNIT_REF>
                <DECIMALS>2</DECIMALS>
                <PRECISION/>
                <IS_NIL>false</IS_NIL>
                <VALUE>12923.00-</VALUE>
            </item>
            <item>
                <NO>2</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.string</XBRL_ID>
                <IS_TUPLE>false</IS_TUPLE>
                <FATHER_ID/>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF/>
                <DECIMALS/>
                <PRECISION/>
                <IS_NIL>false</IS_NIL>
                <VALUE>Test String</VALUE>
            </item>
            <item>
                <NO>3</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.nil</XBRL_ID>
                <IS_TUPLE>false</IS_TUPLE>
                <FATHER_ID/>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF/>
                <DECIMALS/>
                <PRECISION/>
                <IS_NIL>true</IS_NIL>
                <VALUE/>
            </item>
            <item>
                <NO>4</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.tuple1</XBRL_ID>
                <IS_TUPLE>true</IS_TUPLE>
                <FATHER_ID/>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF/>
                <DECIMALS/>
                <PRECISION/>
                <IS_NIL>false</IS_NIL>
                <VALUE/>
            </item>
            <item>
                <NO>5</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.a</XBRL_ID>
                <IS_TUPLE>false</IS_TUPLE>
                <FATHER_ID>bs.ass.tuple1</FATHER_ID>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF/>
                <DECIMALS/>
                <PRECISION/>
                <IS_NIL>false</IS_NIL>
                <VALUE>Value for bs.ass.a</VALUE>
            </item>
            <item>
                <NO>6</NO>
                <NS_PREFIX>de-gaap-ci</NS_PREFIX>
                <XBRL_ID>bs.ass.b</XBRL_ID>
                <IS_TUPLE>false</IS_TUPLE>
                <FATHER_ID>bs.ass.tuple1</FATHER_ID>
                <CONTEXT_REF>D-2012</CONTEXT_REF>
                <UNIT_REF/>
                <DECIMALS/>
                <PRECISION/>
                <IS_NIL>false</IS_NIL>
                <VALUE>Value for bs.ass.b</VALUE>
            </item>
        </CONCEPTS>
        <CONTEXTS>
            <item>
                <ID>D-2012</ID>
                <SCHEME>http://www.rzf-nrw.de/Steuernummer</SCHEME>
                <IDENTIFIER>5117050051729</IDENTIFIER>
                <IS_INSTANT>false</IS_INSTANT>
                <DATE_A>2012-08-28</DATE_A>
                <DATE_B>2012-08-30</DATE_B>
            </item>
            <item>
                <ID>I-2012</ID>
                <SCHEME>http://www.rzf-nrw.de/Steuernummer</SCHEME>
                <IDENTIFIER>5117050051729</IDENTIFIER>
                <IS_INSTANT>true</IS_INSTANT>
                <DATE_A>2012-08-28</DATE_A>
                <DATE_B/>
            </item>
        </CONTEXTS>
        <UNITS>
            <item>
                <ID>EUR</ID>
                <MEASURE_NS>iso4217</MEASURE_NS>
                <MEASURE_VALUE>EUR</MEASURE_VALUE>
            </item>
                        (...)
        </UNITS>
        <NAMESPACES>
            <item>
                <PREFIX>de-gcd</PREFIX>
                <URI>http://www.xbrl.de/taxonomies/de-gcd-2011-09-14</URI>
                <IS_DEFAULT>false</IS_DEFAULT>
            </item>
                        (...)
        </NAMESPACES>
        <SCHEMAS>
            <item>
                <SCHEMA_REF>http://www.xbrl.de/taxonomies/de-gcd-2011-09-14.xsd</SCHEMA_REF>
            </item>
                        (...)
        </SCHEMAS>
    </asx:values>
</asx:abap>

The column IS_TUPLE says that this element is a father node inside the tree. All -elements that have the XBRL_ID of this father inside the column FATHER_ID are supposed to be the children of this father. Hence, if the column FATHER_ID is empty the node has no father.

I want to process these elements recursively with XSLT. The target format is XBRL which is basically XML. Here is my attempt:

<xsl:template match="/">
<xbrl ...>
   <xsl:apply-templates select="/CONCEPTS/item">
      <xsl:with-param name="rec_father_node" select="/" />
   </xsl:apply-templates>
</xbrl>
</xsl:template>

<xsl:template name="tpl_concept" match="/CONCEPTS/item">

    <xsl:param name="rec_father_node"/>

    <xsl:variable name="rec_father_id" select="string($rec_father_node/XBRL_ID/text())"/>

    <xsl:variable name="father_id" select="string(*[local-name()='FATHER_ID'])"/>
    <xsl:variable name="is_tuple" select="string(*[local-name()='IS_TUPLE'])"/>     
    <xsl:variable name="ns_prefix" select="string(*[local-name()='NS_PREFIX'])"/>
    <xsl:variable name="xbrl_id" select="string(*[local-name()='XBRL_ID'])"/>
    <xsl:variable name="name" select="$xbrl_id"/>

    <xsl:if test="$is_tuple = 'false' and $rec_father_id = $father_id">

        <xsl:element name="{$name}">
                      (...)
        </xsl:element>
    </xsl:if>

    <xsl:if test="$is_tuple = 'true' and $rec_father_id = $father_id">
        <xsl:element name="{$name}">
            <xsl:choose>
                <xsl:when test="$is_nil = 'true'">
                    <xsl:attribute name="xsi:nil">true</xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="/CONCEPTS/item">
                        <xsl:with-param name="rec_father_id" select="current()" />
                    </xsl:apply-templates>                  
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>
    </xsl:if>       
</xsl:template>

My idea was the following: nodes that are no father have the string value of ” inside the column FATHER_ID. Therefore, I pass the root node to the parameter rec_father_node to get this initial string. With the recursive call of the same template the parameter rec_father_node contains the node of this father so I can read out the XBRL_ID of this father to only add elements that have this value inside the column FATHER_ID.

My problem is the following: the parameter rec_father_node looses its value passed by the recursion call. The value is always the root node which is passed by the initial <xsl:apply-templates .../> call.

Is there a way to pass a parameter to recursive template calls? Or in general, how can I transform this flat table into a XML node tree with nested elements?

The target of the transformation should look like this (taken names from the example above and added some other nodes for clarity):

<?xml version="1.0" encoding="UTF-8"?>
<xbrl>
    <bs.ass.monetary>12923.00-</bs.ass.monetary>
    <bs.ass.string>Test String</bs.ass.string>
    <bs.ass.nil></bs.ass.nil>
    <bs.ass.tuple1>
        <bs.ass.a>Value for bs.ass.a</bs.ass.a>
        <bs.ass.b>Value for bs.ass.b</bs.ass.b>
    </bs.ass.tuple1>
</xbrl>

Thanks for any help or comments!

  • 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-06-10T14:02:05+00:00Added an answer on June 10, 2026 at 2:02 pm

    What you could do is firstly define a key to look up ‘child’ items based on their FATHER_ID elements.

    <xsl:key name="children" match="item" use="FATHER_ID" />
    

    Firstly though you would start off by matching items with no father

    <xsl:apply-templates select="item[FATHER_ID='']"/>
    

    Then, for items which are ‘tuples’ you could match them, and recursively match their children with a key

    <xsl:template match="item[IS_TUPLE='true']">
       <xsl:element name="{XBRL_ID}">
          <xsl:apply-templates select="key('children', XBRL_ID)" />
       </xsl:element>
    </xsl:template>
    

    You would also have another template for item elements, which would match non-tuples, which would output whatever value you like.

    Try the following XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
       <xsl:key name="children" match="item" use="FATHER_ID"/>
    
       <xsl:template match="/">
             <xsl:apply-templates select="//CONCEPTS"/>
       </xsl:template>
    
       <xsl:template match="CONCEPTS">
          <xbrl>
             <xsl:apply-templates select="item[FATHER_ID='']"/>
          </xbrl>
       </xsl:template>
    
       <xsl:template match="item[IS_TUPLE='true']">
          <xsl:element name="{XBRL_ID}">
             <xsl:apply-templates select="key('children', XBRL_ID)"/>
          </xsl:element>
       </xsl:template>
    
       <xsl:template match="item">
          <xsl:element name="{XBRL_ID}">
             <xsl:value-of select="VALUE" />
          </xsl:element>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample, you get the following

    <xbrl>
       <bs.ass.monetary>12923.00-</bs.ass.monetary>
       <bs.ass.string>Test String</bs.ass.string>
       <bs.ass.nil></bs.ass.nil>
       <bs.ass.tuple1>
          <bs.ass.a>Value for bs.ass.a</bs.ass.a>
          <bs.ass.b>Value for bs.ass.b</bs.ass.b>
       </bs.ass.tuple1>
    </xbrl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to transform some xml into HTML that has the following format: <TR><TD>
I want to transfer data that appears in Arduino to my C# application and
I want to transform a line that looks like this: any text #any text#
I want to write a rename function to replace String names (which represent hierarchical
I want to transfer data from a vertical db layout like this: --------------------- |
I want to transform this data: Thu, 06 Sep 2012 16:15:00 +0200 in the
I want to transform an XML document. The source XML looks like this: <svc:ElementList>
I want to transform a date from this format: 01/07/09 to this jan 07,09
I want to transfer the data from one table in sql to another is
I want to transfer data(21M rows) from mysql database to DynamoDB. I am using

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.