0

Two x ml, one has date ranges like below

20130101-20131231
20120101-20121231
20110101-20111231

Second x ml has dates like below with begindate and enddate tags for each date range and this x ml will have only subset of date ranges. How to find the missing dates using xslt

2012-01-01
2012-12-31

The result should be

2013-01-01
2013-12-31

2011-01-01
2011-12-31

3 Answers3

0

hmm not sure why you tagged your post with "tibco" If you want to do it in tibco businessworks, there are functions like format-date() etc in your mapping functions

If you want to do it in XSLT 1.0, simply use a substring for day/month/year on the orginal date to create a new formatted date like described here: Convert time string in XSLT

Community
  • 1
  • 1
Seb
  • 684
  • 4
  • 11
0

Its not about the formating date, It is two xml's one being the subset of other, we would like to find the dates that the missing from the subset xmls and that will be the result xml.

Thanks Ajay

0

Below is the input xml I've used where dates/main/date are the main list of dates and dates/main/check/dateRange are the ones to be checked for:

<dates>
<main>
    <date>20130101-20131231</date>
    <date>20120101-20121231</date>
    <date>20110101-20111231</date>
</main>
<check>
    <dateRange>
        <from>2012-01-01</from>
        <to>2012-12-31</to>
    </dateRange>
</check>
</dates>

Now, following XSLT, takes this XML as input and gives the desired output:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="text" />
<xsl:strip-space elements="*" />

<xsl:template match="/">
    <xsl:variable name="dateRange" select="//dateRange"/>
    <xsl:for-each select="dates/main/date[not(. = (for $var in $dateRange return concat(translate($var/from,'-',''),'-',translate($var/to,'-',''))))]">
        <xsl:call-template name="writeOut">
            <xsl:with-param name="date" select="."/>
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>

<xsl:template name="writeOut">
    <xsl:param name="date"/>
    <xsl:variable name="from" select="substring-before($date,'-')"/>
    <xsl:variable name="to" select="substring-after($date,'-')"/>

    <xsl:value-of select="concat(substring($from,1,4),'-',substring($from,5,2),'-',substring($from,7))"/>
    <xsl:text>&#10;</xsl:text>
    <xsl:value-of select="concat(substring($to,1,4),'-',substring($to,5,2),'-',substring($to,7))"/>
    <xsl:text>&#10;&#10;</xsl:text>
</xsl:template>

</xsl:stylesheet>
Lingamurthy CS
  • 5,412
  • 2
  • 13
  • 21