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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:42:32+00:00 2026-05-23T19:42:32+00:00

Is it possible to define a custom format for <xsl:number> ? I have the

  • 0

Is it possible to define a custom format for <xsl:number>?

I have the case where a standard alpha-based format is desired, but certain characters in the alphabet are forbidden (strange requirement, but it is what the client requires). For example, the letter i cannot be used, so when using <xsl:number> I should get the sequence: a, b, c, d, e, f, g, h, j, k, …, aa, ab, …, ah, aj, …

The project is using XSLT 2.0 and Saxon, so if a solution exists that is specific to Saxon, that is okay.

Does XSLT 2.0 provide the capability to define a custom format sequence? Does Saxon provide a capability to register a custom sequence for use with <xsl:number>?

  • 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-23T19:42:33+00:00Added an answer on May 23, 2026 at 7:42 pm

    I came up with the following, more generalized solution, after posting my original solution to the problem. The solution is pure XSLT and at the base, still uses <xsl:number>, so should be applicable to any format type.

    <xsl:stylesheet version="2.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:ewh="http://www.earlhood.com/XSL/Transform"
                    exclude-result-prefixes="#all">
    
    <!-- Description: XSLT to generate a alpha formatted sequence
         label (via <xsl:number>), but disallowing specific characters
         from being used.
      -->
    
    <!-- Algorithm: Given the index value of the item to generate
         a label for via <xsl:number>, we adjust the value so the resulting
         label avoids the use of the forbidden characters.
    
         This is achieved by converting the index value into a baseX
         number, with X the number of allowed characters.
    
         The baseX number will be converted into a reverse sequence
         of numbers for each ^E place.  For example, the number 12167
         converted to base23 will generate the following reverse sequence:
    
           Place:    (23^0, 23^1, 23^2, 23^3)
           Sequence: (   0,    0,    0,    1)   // 1000 in base23
    
         Having it in right-to-left order makes processing easier.
    
         Each item in the sequence will be a number from 0 to baseX-1.
    
         With the sequence, we can then just call <xsl:number> on
         each item and reverse concatenate the result.
    
         NOTE: Since <xsl:number> does not like 0 as a given value,
         the sequence must be processed so each item is within the
         range of 1-to-baseX.  For example, the above base23 example
         will be translated to the following:
    
           (23, 22, 22)
      -->
    
    <xsl:output method="xml" indent="yes"/>
    
    <!-- Number of allowed characters: This should be total number of chars of
         format-type desired minus the chars that should be skipped. -->
    <xsl:variable name="lbase" select="23"/>
    <!-- Sequence of character positions not allowed, with 1=>a to 26=>z -->
    <xsl:variable name="lexcs" select="(9,12,15)"/> <!-- i,l,o -->
    
    <!-- Helper Function:
         Convert integer to sequence of number of given base.
         The sequence of numbers is in reverse order: ^0,^1,^2,...^N.
      -->
    <xsl:function name="ewh:get_base_digits" as="item()*">
      <xsl:param name="number" as="xs:integer"/>
      <xsl:param name="to"     as="xs:integer"/>
      <xsl:variable name="Q" select="$number idiv $to"/>
      <xsl:variable name="R" select="$number mod $to"/>
      <xsl:sequence select="$R"/>
      <xsl:if test="$Q gt 0">
        <xsl:sequence select="ewh:get_base_digits($Q,$to)"/>
      </xsl:if>
    </xsl:function>
    
    <!-- Helper Function:
         Compute carry-overs in reverse-base digit sequence.  XSLT starts
         numbering at 1, so we cannot have any 0s.
      -->
    <xsl:function name="ewh:compute_carry_overs" as="item()*">
      <xsl:param name="digits" as="item()*"/>
      <xsl:variable name="d" select="subsequence($digits, 1, 1)"/>
      <xsl:choose>
        <xsl:when test="($d le 0) and (count($digits) = 1)">
          <!-- 0 at end of list, nothing to do -->
        </xsl:when>
        <xsl:when test="$d le 0">
          <!-- If digit <=0, need to perform carry-over operation -->
          <xsl:variable name="next" select="subsequence($digits, 2, 1)"/>
          <xsl:choose>
            <xsl:when test="count($digits) le 2">
              <xsl:sequence select="$lbase + $d"/>
              <xsl:sequence select="ewh:compute_carry_overs($next - 1)"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:sequence select="$lbase + $d"/>
              <xsl:sequence select="ewh:compute_carry_overs(($next - 1,
                  subsequence($digits, 3)))"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:when test="count($digits) le 1">
          <xsl:sequence select="$d"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:sequence select="$d"/>
          <xsl:sequence select="ewh:compute_carry_overs(subsequence($digits, 2))"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:function>
    
    <!-- Helper Function:
         Given a number in the base range, determine number for
         purposes of <xsl:number>.  We loop thru the exclusion
         list and add 1 for each exclusion letter that has
         been passed.  The $digit parameter should be a number
         in the range [1..$lbase].
      -->
    <xsl:function name="ewh:compute_digit_offset" as="xs:integer">
      <xsl:param name="digit"      as="xs:integer"/>
      <xsl:param name="excludes"   as="item()*"/>
      <xsl:variable name="l" select="subsequence($excludes, 1, 1)"/>
      <xsl:variable name="result">
        <xsl:choose>
          <xsl:when test="$digit lt $l">
            <xsl:value-of select="0"/>
          </xsl:when>
          <xsl:when test="count($excludes) = 1">
            <xsl:value-of select="1"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:variable name="rest">
              <xsl:value-of select="ewh:compute_digit_offset($digit+1,
                  subsequence($excludes,2))"/>
            </xsl:variable>
            <xsl:value-of select="1 + $rest"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:value-of select="$result"/>
    </xsl:function>
    
    <!-- Retrieve alpha sequence label.
         This is the main function to call.
      -->
    <xsl:function name="ewh:get-alpha-label" as="xs:string">
      <xsl:param name="number" as="xs:integer"/>
      <xsl:variable name="basedigits"
                    select="ewh:get_base_digits($number,$lbase)"/>
      <xsl:variable name="digits"
                    select="ewh:compute_carry_overs($basedigits)"/>
      <xsl:variable name="result" as="item()*">
        <xsl:for-each select="$digits">
          <xsl:variable name="digit" select="."/>
          <!-- Should not have any 0 values.  If some reason we do,
               we ignore assuming they are trailing items. -->
          <xsl:if test="$digit != 0">
            <xsl:variable name="value">
              <xsl:value-of select="$digit +
                  ewh:compute_digit_offset($digit,$lexcs)"/>
            </xsl:variable>
            <xsl:variable name="number">
              <xsl:number value="$value" format="a"/>
            </xsl:variable>
            <xsl:sequence select="$number"/>
          </xsl:if>
        </xsl:for-each>
      </xsl:variable>
      <xsl:value-of select="string-join(reverse($result),'')"/>
    </xsl:function>
    
    <!-- For testing -->
    <xsl:template match="/">
      <result>
        <xsl:for-each select="(1 to 1000,12166,12167,12168,279840,279841,279842)">
          <value n="{.}"><xsl:value-of select="ewh:get-alpha-label(.)"/></value>
        </xsl:for-each>
      </result>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In VBP its possible to define user defined actions by creating a custom COM
Does anyone know if it possible to define the equivalent of a java custom
Is it possible to define a spring-managed EJB3 hibernate listener? I have this definition
Suppose I have a custom file format, which can be analogous to N tables.
Is it possible to define custom colours for the MKPinAnnotationView colour rather than the
I'm not sure if this is even possible, but here goes: I have a
I know, it's possible to define a QObject with custom properties and expose this
Is it possible to define in XML schema that there must be some certain
Its possible with TinyMCE to define custom URL converter logic as defined in this
For instance, is the following possible: #define definer(x) #define #x?

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.