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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:22:10+00:00 2026-06-11T03:22:10+00:00

<Data> <AA>123</AA> <AA>45658</AA> <AA>123456789</AA> </Data> Output needed: <info> <Numbers id=000000123 /> <Numbers id=000045658 />

  • 0
<Data>
<AA>123</AA>
  <AA>45658</AA>
  <AA>123456789</AA> 
</Data>

Output needed:

<info>
  <Numbers id="000000123" />
  <Numbers id="000045658" />
  <Numbers id="123456789" />
</info>

Condition:

I need to check for the string length of value of the element AA. If the length is less than 9 I need to append ‘0’ s to make it 9 digit in length.

XSLT wrote:

<xsl:template match="Data">   
  <info>
       <xsl:for-each select="AA">
              <Numbers>
                <xsl:attribute name="id">
                  <xsl:variable name="numlenght">
                  <xsl:value-of select="string-length(.)" />
                    </xsl:variable>
                  <xsl:choose>
                    <xsl:when test="$numlenght&lt;9">
                      <xsl:variable name="balance">
                        <xsl:value-of select="9-$numlenght"/>
                      </xsl:variable>
                      <xsl:for-each select="//*[position() &lt;$balance]">
                        <xsl:value-of select="'0'"/>
                      </xsl:for-each>

                    </xsl:when>
                                      </xsl:choose>
                  <xsl:value-of select="."/>

                </xsl:attribute>
              </Numbers>
            </xsl:for-each>
  </info>
        </xsl:template>

I am not getting the exact output.

Can any one suggest how to do that?

  • 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-11T03:22:11+00:00Added an answer on June 11, 2026 at 3:22 am

    This requires less memory:

    concat(substring('000000000', string-length() +1), .)
    

    Here is a complete transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="/*">
         <info><xsl:apply-templates/></info>
     </xsl:template>
    
     <xsl:template match="AA">
      <Numbers id="{concat(substring('000000000', string-length() +1), .)}"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <Data>
        <AA>123</AA>
        <AA>45658</AA>
        <AA>123456789</AA>
    </Data>
    

    the wanted, correct result is produced:

    <info>
       <Numbers id="000000123"/>
       <Numbers id="000045658"/>
       <Numbers id="123456789"/>
    </info>
    

    Explanation:

    The expression:

    concat(substring('000000000', string-length() +1), .)
    

    doesn’t construct a string with length greater than 9 (as in another answer, that after this extracts a substring of the longer than 9 characters string).

    In contrast, it extracts only the necessary for padding number of 0 characters and then concatenates them to the current node’s string value.

    Do note:

    This:

      <Numbers id="{concat(substring('000000000', string-length() +1), .)}"/>
    

    can be simplified further to this:

      <Numbers id="{substring('000000000', string-length() +1)}{.}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi is it possible to cut string like this: String in data columns: ,123,456
I've got a data-123 string. How can I remove data- from the string while
Here is dataset: set.seed(123) myd <- data.frame (class = rep(1:4, each = 100), yvar
Say I have data like this: <option value=abc >Test - 123</option> <option value=def >Test
The way being suppose the data is 123 134 2312 32131 2131231 211212 It
Say I have a range of data from A1:Y55 containg data like 123 UID
I've got a table of transaction data for several locations and I need to
I have a table that looks like this A B ID1 data 123 ID2
Here is data: set.seed(123) mat <- matrix(rnorm(5000, 0.5, 0.2), 50) heatmap (mat) mat[mat >
We can have { data: hello }, { data: 123 } in the same

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.