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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:07:05+00:00 2026-05-11T19:07:05+00:00

Hey all, I have highly repetitive data with a depth of 5 nodes deep

  • 0

Hey all, I have highly repetitive data with a depth of 5 nodes deep (including the root) that needs to be broken apart. (I’ll include a fast sample in a minute.) What I’m looking to do is parse a ~5mb XML file into smaller sub-files based on the 3rd-depth nodes. But after that, it gets more complicated.

The task’s requirements are these:

  1. Sub-files must maintain the hierarchical parents of the 3rd level node which is extracted, including their attributes.
  2. Sub-files must retain all attributes and children nodes.
  3. If XSLT cannot handle the job, attempt it in Ruby. If you aren’t good at XSLT, but can tell me how to do it in Ruby or even Python, please feel free to contribute an answer in those languages. (Else try and stick with XSLT or pseudo-code.)

DOM Hierarchy:

<xml attr="whatever">
  <major-group name="whatever">
    <minor-group name="whatever">
      <another-group name="whatever">
        <last-node name="whatever"></last-node>
      </another-group>
    </minor-group>
  </major-group>
</xml>

Which I need to split on the minor-group element while retaining both its children and direct parents, and put all that (for each minor-group) in an external file. I have several files to split in this manner.

And… having never before parsed XML in Ruby, and having just begun using XSLT, I cannot yet write a script to accomplish my task with either.

I’m curious to see if XSLT is up to the task. :>

Edit:

Here’s my resulting code, with the ability to show a stylesheet at the beginning of the file.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:output method="xml"/>
  <xsl:template match="minor-group">
    <xsl:variable name="filename"><xsl:value-of select="concat(@name,'.xml')"/></xsl:variable>
    <xsl:result-document href="{$filename}">
      <xsl:text disable-output-escaping="yes">
        <![CDATA[<?xml-stylesheet type="text/xsl" href="../web.xslt"?>]]>
      </xsl:text> 
      <xml>
        <xsl:attribute name="whatever"><xsl:value-of select="../../@whatever" /></xsl:attribute>
        <major-group>
          <xsl:attribute name="whatever"><xsl:value-of select="../@whatever" /></xsl:attribute>
          <xsl:copy-of select="."/>
        </major-group>
      </xml>
    </xsl:result-document>
  </xsl:template>
</xsl:stylesheet>
  • 1 1 Answer
  • 1 View
  • 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-11T19:07:05+00:00Added an answer on May 11, 2026 at 7:07 pm

    To extract the list of “minor group” elements, one of the following XPath expressions would be required.

    /xml/major-group/minor-group    (the explicit way)
    /*/*/*                          (the generic, any-third-level-element way)
    

    In a scripting language of your choice, read the document into a DOM, construct a loop over the XPath query, writing the results to different output files.

    With XSLT 1.0 it is not possible to generate more than one output document at a time. Hovever, XSLT 2.0 supports this via the <xsl:result-document> instruction.

    If you have an XSLT 2.0 engine at your disposal, you could try that route. A random page I found at IBM’s developerWorks website shows how to get started: Tip: Create multiple files in XSLT 2.0

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

Sidebar

Related Questions

Hey all, I'm about to rip my hair out. I have this client that
Hey all, i have made a simple form that mimiks the jQuery GROWL effect
hey all. I have a table in my DB that has about a thousand
Hey all, I've noticed that if I have a style setup for a treeview,
Hey all. I have written a program that sequentially scans certain parts of a
Hey all. I have a project that will require user input of anywhere from
Hey all, I have a basic HTML contact form that goes to a .php
Hey all i have an XML file that i am trying to loop though.
Hey all, have a slight problem here. In CakePHP I have a controller that
hey all i have a problem in webservice that i am consuming. it takes

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.