0

I am having the Date field as below

    <Input>
<date>08/26/2020</date>
</Input>

i would need to parse it as like below

<date>2020-08-26</date>

I have tried using below xpath funtion in XSLT, which is not producing any result

xp20:format-dateTime(/Input/date,'[Y0001]-[M01]-[D01]')

Any help here??

2 Answers 2

1

Using replace you can reorder the components, if you want to create an XSLT/XPath xs:date, additionally use the constructor function:

  <xsl:template match="date">
      <xsl:copy>
          <xsl:value-of select="xs:date(replace(., '([0-9]{2})/([0-9]{2})/([0-9]{4})', '$3-$1-$2'))"/>
      </xsl:copy>
  </xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

0

What you could do is, extract sub strings, and re-join them as needed.

<date><xsl:value-of select="concat(substring-after(substring-after(date/text(),'/'),'/'), '-', substring-before(date/text(),'/'), '-', substring-before(substring-after(date/text(),'/'),'/'))" /></date>

or better use a template for this:

<xsl:template name="format_date">
        <xsl:param name="date" />
        <xsl:value-of select="concat( substring($date, 7, 2),'.',substring($date, 5, 2), '.', substring($date, 1, 4), ', ', substring($date, 9, 2),':',substring($date, 11, 2),'h' )" />
    </xsl:template>

and pass the date as param (with-param).

which'll give you the desired <date>2020-08-26</date>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.