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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:06:52+00:00 2026-06-11T06:06:52+00:00

I am quite new to xsl and functional programming, so I’ll be grateful for

  • 0

I am quite new to xsl and functional programming, so I’ll be grateful for help on this one:

I have a template that transforms some xml and provides an output. The problem is that there are many elements of type xs:date, all in different contexts, that must be localized. I use a concatenation of substrings of these xs:dates to produce a localized date pattern strings.

As you can guess this causes a lot of copy-paste “substring-this and substring-that“. How can I write a template that will automatically transform all the elements of type xs:date to localized strings preserving all the context-aware transformations?

My xsl is something like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">  
    <xsl:output method="html" encoding="utf-8"/>
        <xsl:template match="/">
        ...
        <input value="{substring(/select/a/date 9,2)}.{substring(/select/a/date, 6,2)}.{substring(/select/a/date 1,4)}">
        ...
        <!-- assume that following examples are also with substrings -->
        <div><xsl:value-of select="different-path/to_date"/></div>
        ...
        <table>
        <tr><td><xsl:value-of select="path/to/another/date"/></td></tr>
        </table>
        <apply-templates/>
        </xsl:template>
        <xsl:template match="something else">
        <!-- more dates here -->
        </xsl:template>
</xsl:stylesheet>

I hope I managed to make my question clear =)

UPD: Here is an example of xml:

<REQUEST>
    <header>
        <... />
        <ref>
            <ref_date type="xs:date">1970-01-01</ref_date>
        </ref>
    </header>

    <general>
        <.../>
        <info>
            <.../>
            <date type="xs:date">1970-01-01</date>
            <ExpireDate type="xs:date">1970-01-01</ExpireDate>
            <RealDate type="xs:date">1970-01-01</RealDate>
            <templateDetails>template details</templateDetails>
            <effectiveDate type="xs:date">1970-01-01</effectiveDate>
        </info>

        <party>
            <.../>
                <date type="xs:date">1970-01-01</date>
        </party>

        <!-- many other parts of such kind -->
    </general>

</REQUEST>

As for the output, there are many different options. The main thing is that these values must be set as a value of different html objects, such as tables, input fields and so on. You can see an example in the xsl listing.

P.S. I’m using xsl 1.0.

  • 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-11T06:06:53+00:00Added an answer on June 11, 2026 at 6:06 am

    What you could do is add a template to match any element which has an @type attribute of ‘xs:date’, and do you substring manipulation in there

    <xsl:template match="*[@type='xs:date']">
       <xsl:value-of select="translate(., '-', '/')" />
    </xsl:template>
    

    In this case I am just replacing the hyphens by slashes as an example.

    Then, instead of using xsl:value-of….

    <div><xsl:value-of select="different-path/to_date"/></div>  
    

    You could use xsl:apply-templates

    <div><xsl:apply-templates select="different-path/to_date"/></div>  
    

    Consider this XSLT as an example

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">        
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:template match="*[@type='xs:date']">
            <xsl:copy>
                <xsl:value-of select="translate(., '-', '/')" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    In this case, all this XSLT is doing is copying the XML document as-is, but changing the date elements.

    If you wanted to use the date template for other elements, or values, you could also make it a named-template, like so

    <xsl:template match="*[@type='xs:date']" name="date">
        <xsl:param name="date" select="." />
        <xsl:value-of select="translate($date, '-', '/')" />
    </xsl:template>
    

    This would allow you to also call it much like a function. For example, to format a data and add as an attribute you could do the following:

    <input>
       <xsl:attribute name="value">
           <xsl:call-template name="date">
              <xsl:with-param name="date" select="/select/a/date" />
           </xsl:call-template>
       </xsl:attribute>
    </input>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quite new to this but i have created a SQL script that groups by
Quite new to Linq, and I'm struggling with this one. Basically I have a
I am quite new to mongoid and rails. So I have some troubles to
Am quite new to namespacing etc so hopefully this will be straightforward. I have
Quite new to this mocking thing, I have a couple of questions. Correct me
Quite new to RIA Services but i am progressing... I noticed that some methods
This is a re-work/new question after I got my previous one quite wrong by
Still quite new to Python. I have a problem similar to this question .
Im quite new at this .....sorry in advance. I have created an app in
I'm quite new to CSS / HTML, and can't find the cause of this

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.