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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:45:51+00:00 2026-05-19T16:45:51+00:00

is it possible to do the following in xsl. I’m tring to split the

  • 0

is it possible to do the following in xsl. I’m tring to split the contents of an element and create sub-elements based on the split. To make things trickier there are the occasional exception (ie node-4 doesn’t get split). I’m wondering if there is a way i can do this without explicit splits hardcoded for each element. Again, not sure if this is possible. thanks for the help!

original XML:

<document>
  <node>
    <node-1>hello world1</node-1>
    <node-2>hello^world2</node-2>
    <node-3>hello^world3</node-3>
    <node-4>hello^world4</node-4>
  </node>
</document>

transformed XML

<document>
  <node>
    <node-1>hello world1</node-1>
    <node-2>
      <node2-1>hello</node2-1>
      <node2-2>world2</node2-2>
    </node-2>
    <node-3>
      <node3-1>hello</node3-1>
      <node3-2>world3</node3-2>
    </node-3>
    <node-4>hello^world4</node-4>
  </node>
</document>
  • 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-19T16:45:52+00:00Added an answer on May 19, 2026 at 4:45 pm

    Here’s an XSL 1.0 solution. I presume that the inconsistency in node-4 in your sample output was just a typo. Otherwise you’ll have to define why node3 was split and node4 wasn’t.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
    
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/">
        <document>
          <node>
            <xsl:apply-templates select="document/node/*"/>
          </node>
        </document>
      </xsl:template>
    
      <xsl:template match="*">
        <xsl:variable name="tag" select="name()"/>
    
        <xsl:choose>
    
          <xsl:when test="contains(text(),'^')">
            <xsl:element name="{$tag}">
              <xsl:element name="{concat($tag,'-1')}">
                <xsl:value-of select="substring-before(text(),'^')"/>
              </xsl:element>
              <xsl:element name="{concat($tag,'-2')}">
                <xsl:value-of select="substring-after(text(),'^')"/>
              </xsl:element>
            </xsl:element>
          </xsl:when>
    
          <xsl:otherwise>
            <xsl:copy-of select="."/>
          </xsl:otherwise>
    
        </xsl:choose>
    
      </xsl:template>
    
    </xsl:stylesheet>
    

    This works as long as all the nodes you want split are at the same level, under /document/node. If the real document structure is different you will have to tweak the solution to match.

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

Sidebar

Related Questions

I was wondering if the following is possible. Create a class that accepts an
If have a following element in my XSL file: <xsl:value-of select=replace(lower-case(@name), '_([a-z0-9])', '$1') />
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
Is it possible to sort the following xml with xsl (sort SubGroup in Group
In an AutoFixture-based test, I'm trying to express as cleanly as possible the following:
How to I make the following possible? models.py class Article(models.Model): #... regions = models.ManyToManyField(Region)
Is there some way to make the following possible, or should it be done
How is it possible that following code even compiles? As far as I can
Is it possible in the following scenario to define dedicated constructors for certain specializations
Is it possible to transform following code to Linq that it will look like

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.