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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:54:19+00:00 2026-05-29T08:54:19+00:00

I have some XML like so: <subsection number=5> <p> (5) The <link path=123>Secretary of

  • 0

I have some XML like so:

    <subsection number="5">
       <p>
         (5) The <link path="123">Secretary of State</link> shall appoint such as....
      </p>
    </subsection>

I can’t change the XML and I need to strip out the (5) at the start of the paragraph and use the number attribute in the parent tag to create a new paragraph number with appropriate markup:

<xsl:template match="subsection/p">
        <xsl:variable name="number">
            <xsl:text>(</xsl:text>
            <xsl:value-of select="../@number"/>
            <xsl:text>)</xsl:text>
       </xsl:variable>
       <xsl:variable name="copy">
            <xsl:value-of select="."/>
       </xsl:variable>
       <p>
          <span class="indent">
            <xsl:value-of select="$number" />
          </span>
          <span class="copy">
            <xsl:value-of select="substring-after($copy, $number)" />
          </span>
       </p>
</xsl:template>

The problem is the rest of the paragraph may contain more XML that needs to be transformed, such as the link tag in the example.

I don’t know how to apply templates to this once I’ve used the substring-after function.

  • 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-29T08:54:20+00:00Added an answer on May 29, 2026 at 8:54 am

    An explicit approach is to handle the first text child of subsection/p elements separately from all other children. For demonstration purposes, I’ve also added a template for converting link elements into a elements.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:template match="subsection/p/text()[1]">
            <xsl:value-of select="concat('(', ../../@number, ')')"/>
        </xsl:template>
        <xsl:template match="subsection/p">
            <p>
                <span class="indent">
                    <xsl:apply-templates select="text()[1]"/>
                </span>
                <span class="copy">
                    <xsl:apply-templates select="*|text()[not(position()=1)]"/>
                </span>
            </p>
        </xsl:template>
        <xsl:template match="subsection/p/link">
            <a href="{@path}"><xsl:value-of select="."/></a>
        </xsl:template>
    </xsl:stylesheet>
    

    This stylesheet produces the following output:

    <p><span class="indent">(5)</span><span class="copy">
    <a href="123">Secretary of State</a>shall appoint such as....</span></p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
If I have some xml containing things like the following mediawiki markup: ...collected in
I have some XML which contains records and sub records, like this: <data> <record
I have some data in an XML element that looks like this: <?xml version=1.0
I have some values in a configuration file (XML file) with some values like
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
I have an XML file that I would like to map some attributes of
I have some XML like this: <root> <do-not-sort> <z/> <y/> </do-not-sort> <sortable> <e f=fog
Suppose I have some XML like this: <section name=SampleSection> <item name=ScoredItem1> <attributes> <scored data_type=boolean

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.