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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:12:46+00:00 2026-05-23T16:12:46+00:00

I’m looking for an xslt that does the following: With the input xml of,

  • 0

I’m looking for an xslt that does the following:

With the input xml of, for example:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <foo1>bar1</foo1>
    <foo2>bar2^bar3^bar4</foo2>
    <foo3>bar3^bar3</foo3>
    <unknown>more data</unknown>
</root>

I want to copy all of the existing nodes to the resultant xml. I won’t know what all the nodes are, i.e. I won’t know that I’m receiving a foo1 node, I just want to copy them over directly. For certain nodes though, I do know what they are and I want to split them by a delimiter and number them accordingly, as below.

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <foo1>bar1</foo1>
    <foo2>
        <foo2-1>bar2</foo2-1>
        <foo2-2>bar3</food2-2>
        <foo2-3>bar4</foo2-3>
    </foo2>
    <foo3>
        <foo3-1>bar3</foo3-1>
        <foo3-2>bar3</food2-2>
    </foo3>
    <unknown>more data</unknown>
</root>

Any help would be greatly appreciated.

Thanks.

  • 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-23T16:12:46+00:00Added an answer on May 23, 2026 at 4:12 pm

    This is fairly easy to do in XSLT 2.0:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:output indent="yes"/>
    
     <xsl:template match="@*|node()">
         <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
         </xsl:copy>
     </xsl:template>
    
    <xsl:template match="text()[contains(.,'^')]">  
        <xsl:variable name="elementName" select="name(..)"/>
        <xsl:for-each select="tokenize(.,'\^')">
             <xsl:element name="{$elementName}-{position()}">
                <xsl:value-of select="."/>
            </xsl:element>
        </xsl:for-each>  
    </xsl:template>
    
    </xsl:stylesheet>
    

    In XSLT 1.0 you would need to use a recursive template call. For example:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output indent="yes"/>
    
     <xsl:template match="@*|node()">
         <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
         </xsl:copy>
     </xsl:template>
    
    <xsl:template match="text()[contains(.,'^')]">  
        <xsl:variable name="elementName" select="name(..)"/>
    
        <xsl:call-template name="splitIntoElements">
            <xsl:with-param name="baseName" select="name(..)" />
            <xsl:with-param name="txt" select="." />    
        </xsl:call-template>
    
    </xsl:template>
    
    <xsl:template name="splitIntoElements">
        <xsl:param name="baseName" />
        <xsl:param name="txt" />
        <xsl:param name="delimiter" select="'^'" />
        <xsl:param name="index" select="1" />
    
        <xsl:variable name="first" select="substring-before($txt, $delimiter)" />
        <xsl:variable name="remaining" select="substring-after($txt, $delimiter)" />
    
        <xsl:element name="{$baseName}-{$index}">
            <xsl:choose>
                <xsl:when test="$first">
                    <xsl:value-of select="$first" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$txt" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>
    
        <xsl:if test="$remaining">
            <xsl:call-template name="splitIntoElements">
                <xsl:with-param name="baseName" select="$baseName" />
                <xsl:with-param name="txt" select="$remaining" />
                <xsl:with-param name="index" select="$index+1" />
                <xsl:with-param name="delimiter" select="$delimiter" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.