Get list of dates based on condition XSLT 2.0
up vote
0
down vote
favorite
I have this scenario wherein:
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:First_Day
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:First_Day
towd:End_Date
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:Start_Date
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:Start_Date
towd:End_Date
Also, each date needs to get another value depending on what day they are. If it's 09-11-2018 (dd-MM-yyyy) which is Friday (vendredi in French), it should get the value from wd:F01_vendredi
.
For reference:
lundi (Monday)
mardi (Tuesday)
mercredi (Wednesday)
jeudi (Thursday)
vendredi (Friday)
samedi (Saturday)
dimanche (Sunday)
Here is the XML:
<wd:Report_Data xmlns:wd="urn:com.report/F03">
<wd:Report_Entry>
<wd:ID>00000001</wd:ID>
<wd:LOA>
<wd:Type>XYZ</wd:Type>
<wd:First_Day>09-11-2018</wd:First_Day>
<wd:F03_First_Day>vendredi</wd:F03_First_Day>
<wd:F03_Last_Day>12-11-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>0</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>1</wd:F01_lundi>
<wd:F01_mardi>2</wd:F01_mardi>
<wd:F01_mercredi>3</wd:F01_mercredi>
<wd:F01_jeudi>4</wd:F01_jeudi>
<wd:F01_vendredi>5</wd:F01_vendredi>
<wd:F01_samedi>6</wd:F01_samedi>
<wd:F01_dimanche>7</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:ID>00000002</wd:ID>
<wd:LOA>
<wd:Type>ABC</wd:Type>
<wd:First_Day>25-06-2018</wd:First_Day>
<wd:F03_First_Day>lundi</wd:F03_First_Day>
<wd:F03_Last_Day>03-12-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>1</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>6</wd:F01_lundi>
<wd:F01_mardi>5</wd:F01_mardi>
<wd:F01_mercredi>4</wd:F01_mercredi>
<wd:F01_jeudi>3</wd:F01_jeudi>
<wd:F01_vendredi>2</wd:F01_vendredi>
<wd:F01_samedi>1</wd:F01_samedi>
<wd:F01_dimanche>0</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
</wd:Report_Data>
My desired output is:
00000001;09-11-2018;XYZ;5
00000001;10-11-2018;XYZ;6
00000001;11-11-2018;XYZ;7
00000001;12-11-2018;XYZ;1
00000002;01-11-2018;ABC;3
00000002;02-11-2018;ABC;2
...
...
...
00000002;30-11-2018;ABC;2
Thanks!
xml xslt text xslt-2.0
add a comment |
up vote
0
down vote
favorite
I have this scenario wherein:
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:First_Day
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:First_Day
towd:End_Date
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:Start_Date
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:Start_Date
towd:End_Date
Also, each date needs to get another value depending on what day they are. If it's 09-11-2018 (dd-MM-yyyy) which is Friday (vendredi in French), it should get the value from wd:F01_vendredi
.
For reference:
lundi (Monday)
mardi (Tuesday)
mercredi (Wednesday)
jeudi (Thursday)
vendredi (Friday)
samedi (Saturday)
dimanche (Sunday)
Here is the XML:
<wd:Report_Data xmlns:wd="urn:com.report/F03">
<wd:Report_Entry>
<wd:ID>00000001</wd:ID>
<wd:LOA>
<wd:Type>XYZ</wd:Type>
<wd:First_Day>09-11-2018</wd:First_Day>
<wd:F03_First_Day>vendredi</wd:F03_First_Day>
<wd:F03_Last_Day>12-11-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>0</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>1</wd:F01_lundi>
<wd:F01_mardi>2</wd:F01_mardi>
<wd:F01_mercredi>3</wd:F01_mercredi>
<wd:F01_jeudi>4</wd:F01_jeudi>
<wd:F01_vendredi>5</wd:F01_vendredi>
<wd:F01_samedi>6</wd:F01_samedi>
<wd:F01_dimanche>7</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:ID>00000002</wd:ID>
<wd:LOA>
<wd:Type>ABC</wd:Type>
<wd:First_Day>25-06-2018</wd:First_Day>
<wd:F03_First_Day>lundi</wd:F03_First_Day>
<wd:F03_Last_Day>03-12-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>1</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>6</wd:F01_lundi>
<wd:F01_mardi>5</wd:F01_mardi>
<wd:F01_mercredi>4</wd:F01_mercredi>
<wd:F01_jeudi>3</wd:F01_jeudi>
<wd:F01_vendredi>2</wd:F01_vendredi>
<wd:F01_samedi>1</wd:F01_samedi>
<wd:F01_dimanche>0</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
</wd:Report_Data>
My desired output is:
00000001;09-11-2018;XYZ;5
00000001;10-11-2018;XYZ;6
00000001;11-11-2018;XYZ;7
00000001;12-11-2018;XYZ;1
00000002;01-11-2018;ABC;3
00000002;02-11-2018;ABC;2
...
...
...
00000002;30-11-2018;ABC;2
Thanks!
xml xslt text xslt-2.0
1
What do you have so far?
– michael.hor257k
Nov 21 at 20:15
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this scenario wherein:
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:First_Day
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:First_Day
towd:End_Date
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:Start_Date
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:Start_Date
towd:End_Date
Also, each date needs to get another value depending on what day they are. If it's 09-11-2018 (dd-MM-yyyy) which is Friday (vendredi in French), it should get the value from wd:F01_vendredi
.
For reference:
lundi (Monday)
mardi (Tuesday)
mercredi (Wednesday)
jeudi (Thursday)
vendredi (Friday)
samedi (Saturday)
dimanche (Sunday)
Here is the XML:
<wd:Report_Data xmlns:wd="urn:com.report/F03">
<wd:Report_Entry>
<wd:ID>00000001</wd:ID>
<wd:LOA>
<wd:Type>XYZ</wd:Type>
<wd:First_Day>09-11-2018</wd:First_Day>
<wd:F03_First_Day>vendredi</wd:F03_First_Day>
<wd:F03_Last_Day>12-11-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>0</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>1</wd:F01_lundi>
<wd:F01_mardi>2</wd:F01_mardi>
<wd:F01_mercredi>3</wd:F01_mercredi>
<wd:F01_jeudi>4</wd:F01_jeudi>
<wd:F01_vendredi>5</wd:F01_vendredi>
<wd:F01_samedi>6</wd:F01_samedi>
<wd:F01_dimanche>7</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:ID>00000002</wd:ID>
<wd:LOA>
<wd:Type>ABC</wd:Type>
<wd:First_Day>25-06-2018</wd:First_Day>
<wd:F03_First_Day>lundi</wd:F03_First_Day>
<wd:F03_Last_Day>03-12-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>1</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>6</wd:F01_lundi>
<wd:F01_mardi>5</wd:F01_mardi>
<wd:F01_mercredi>4</wd:F01_mercredi>
<wd:F01_jeudi>3</wd:F01_jeudi>
<wd:F01_vendredi>2</wd:F01_vendredi>
<wd:F01_samedi>1</wd:F01_samedi>
<wd:F01_dimanche>0</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
</wd:Report_Data>
My desired output is:
00000001;09-11-2018;XYZ;5
00000001;10-11-2018;XYZ;6
00000001;11-11-2018;XYZ;7
00000001;12-11-2018;XYZ;1
00000002;01-11-2018;ABC;3
00000002;02-11-2018;ABC;2
...
...
...
00000002;30-11-2018;ABC;2
Thanks!
xml xslt text xslt-2.0
I have this scenario wherein:
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:First_Day
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 0 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:First_Day
towd:End_Date
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is less than or equal towd:End_Date
, get the dates fromwd:Start_Date
towd:F03_Last_Day
if
wd:F03_First_Start
is equal to 1 andwd:F03_Last_Day
is greater thanwd:End_Date
, get the dates fromwd:Start_Date
towd:End_Date
Also, each date needs to get another value depending on what day they are. If it's 09-11-2018 (dd-MM-yyyy) which is Friday (vendredi in French), it should get the value from wd:F01_vendredi
.
For reference:
lundi (Monday)
mardi (Tuesday)
mercredi (Wednesday)
jeudi (Thursday)
vendredi (Friday)
samedi (Saturday)
dimanche (Sunday)
Here is the XML:
<wd:Report_Data xmlns:wd="urn:com.report/F03">
<wd:Report_Entry>
<wd:ID>00000001</wd:ID>
<wd:LOA>
<wd:Type>XYZ</wd:Type>
<wd:First_Day>09-11-2018</wd:First_Day>
<wd:F03_First_Day>vendredi</wd:F03_First_Day>
<wd:F03_Last_Day>12-11-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>0</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>1</wd:F01_lundi>
<wd:F01_mardi>2</wd:F01_mardi>
<wd:F01_mercredi>3</wd:F01_mercredi>
<wd:F01_jeudi>4</wd:F01_jeudi>
<wd:F01_vendredi>5</wd:F01_vendredi>
<wd:F01_samedi>6</wd:F01_samedi>
<wd:F01_dimanche>7</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:ID>00000002</wd:ID>
<wd:LOA>
<wd:Type>ABC</wd:Type>
<wd:First_Day>25-06-2018</wd:First_Day>
<wd:F03_First_Day>lundi</wd:F03_First_Day>
<wd:F03_Last_Day>03-12-2018</wd:F03_Last_Day>
<wd:F03_Last>lundi</wd:F03_Last>
<wd:F03_First_Start>1</wd:F03_First_Start>
</wd:LOA>
<wd:F01_lundi>6</wd:F01_lundi>
<wd:F01_mardi>5</wd:F01_mardi>
<wd:F01_mercredi>4</wd:F01_mercredi>
<wd:F01_jeudi>3</wd:F01_jeudi>
<wd:F01_vendredi>2</wd:F01_vendredi>
<wd:F01_samedi>1</wd:F01_samedi>
<wd:F01_dimanche>0</wd:F01_dimanche>
<wd:Start_Date>01-11-2018</wd:Start_Date>
<wd:F03_Start_Day>jeudi</wd:F03_Start_Day>
<wd:End_Date>30-11-2018</wd:End_Date>
<wd:F03_End_Day>vendredi</wd:F03_End_Day>
</wd:Report_Entry>
</wd:Report_Data>
My desired output is:
00000001;09-11-2018;XYZ;5
00000001;10-11-2018;XYZ;6
00000001;11-11-2018;XYZ;7
00000001;12-11-2018;XYZ;1
00000002;01-11-2018;ABC;3
00000002;02-11-2018;ABC;2
...
...
...
00000002;30-11-2018;ABC;2
Thanks!
xml xslt text xslt-2.0
xml xslt text xslt-2.0
edited 2 days ago
asked Nov 21 at 18:48
Carla
416
416
1
What do you have so far?
– michael.hor257k
Nov 21 at 20:15
add a comment |
1
What do you have so far?
– michael.hor257k
Nov 21 at 20:15
1
1
What do you have so far?
– michael.hor257k
Nov 21 at 20:15
What do you have so far?
– michael.hor257k
Nov 21 at 20:15
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You could create a function to create an XSLT/XPath xs:date
from your date format, then you can set up templates for your conditions and process the dates, here is an example for the first of your conditions:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || lower-case(format-date($date, '[F]', 'fr', 'AD', 'FR'))]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Note that this requires an XSLT 3 processor like Saxon PE or EE to support the extraction of the fr
french week day name directly from the xs:date
using the format-date
function with e.g. '[F]', 'fr', unfortunately the HE version of Saxon does not support that, there you get the English name or the English week day number so for HE you could try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || $month-names[xs:integer(format-date($date, '[F1]', 'en', (), ()))]]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Example at https://xsltfiddle.liberty-development.net/nc4NzRr/1. For XSLT 2 you could need to replace the use of the ||
string concatenation operator with calls to the concat
function: http://xsltransform.hikmatu.com/nc4NzPV.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You could create a function to create an XSLT/XPath xs:date
from your date format, then you can set up templates for your conditions and process the dates, here is an example for the first of your conditions:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || lower-case(format-date($date, '[F]', 'fr', 'AD', 'FR'))]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Note that this requires an XSLT 3 processor like Saxon PE or EE to support the extraction of the fr
french week day name directly from the xs:date
using the format-date
function with e.g. '[F]', 'fr', unfortunately the HE version of Saxon does not support that, there you get the English name or the English week day number so for HE you could try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || $month-names[xs:integer(format-date($date, '[F1]', 'en', (), ()))]]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Example at https://xsltfiddle.liberty-development.net/nc4NzRr/1. For XSLT 2 you could need to replace the use of the ||
string concatenation operator with calls to the concat
function: http://xsltransform.hikmatu.com/nc4NzPV.
add a comment |
up vote
0
down vote
accepted
You could create a function to create an XSLT/XPath xs:date
from your date format, then you can set up templates for your conditions and process the dates, here is an example for the first of your conditions:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || lower-case(format-date($date, '[F]', 'fr', 'AD', 'FR'))]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Note that this requires an XSLT 3 processor like Saxon PE or EE to support the extraction of the fr
french week day name directly from the xs:date
using the format-date
function with e.g. '[F]', 'fr', unfortunately the HE version of Saxon does not support that, there you get the English name or the English week day number so for HE you could try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || $month-names[xs:integer(format-date($date, '[F1]', 'en', (), ()))]]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Example at https://xsltfiddle.liberty-development.net/nc4NzRr/1. For XSLT 2 you could need to replace the use of the ||
string concatenation operator with calls to the concat
function: http://xsltransform.hikmatu.com/nc4NzPV.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You could create a function to create an XSLT/XPath xs:date
from your date format, then you can set up templates for your conditions and process the dates, here is an example for the first of your conditions:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || lower-case(format-date($date, '[F]', 'fr', 'AD', 'FR'))]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Note that this requires an XSLT 3 processor like Saxon PE or EE to support the extraction of the fr
french week day name directly from the xs:date
using the format-date
function with e.g. '[F]', 'fr', unfortunately the HE version of Saxon does not support that, there you get the English name or the English week day number so for HE you could try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || $month-names[xs:integer(format-date($date, '[F1]', 'en', (), ()))]]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Example at https://xsltfiddle.liberty-development.net/nc4NzRr/1. For XSLT 2 you could need to replace the use of the ||
string concatenation operator with calls to the concat
function: http://xsltransform.hikmatu.com/nc4NzPV.
You could create a function to create an XSLT/XPath xs:date
from your date format, then you can set up templates for your conditions and process the dates, here is an example for the first of your conditions:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || lower-case(format-date($date, '[F]', 'fr', 'AD', 'FR'))]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Note that this requires an XSLT 3 processor like Saxon PE or EE to support the extraction of the fr
french week day name directly from the xs:date
using the format-date
function with e.g. '[F]', 'fr', unfortunately the HE version of Saxon does not support that, there you get the English name or the English week day number so for HE you could try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="urn:com.report/F03"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
version="3.0">
<xsl:param name="month-names" as="xs:string+"
select="'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:function name="mf:createDate" as="xs:date">
<xsl:param name="date" as="xs:string"/>
<xsl:sequence select="xs:date(replace($date, '([0-9]{2})-([0-9]{2})-([0-9]{4})', '$3-$2-$1'))"/>
</xsl:function>
<xsl:template match="Report_Entry[LOA/F03_First_Start = 0 and mf:createDate(LOA/F03_Last_Day) le mf:createDate(End_Date)]">
<xsl:apply-templates select="." mode="date">
<xsl:with-param name="date" select="mf:createDate(LOA/First_Day)"/>
<xsl:with-param name="last-date" select="mf:createDate(LOA/F03_Last_Day)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Report_Entry" mode="date">
<xsl:param name="date"/>
<xsl:param name="last-date"/>
<xsl:value-of select="ID, format-date($date, '[D01]-[M01]-[Y0001]'), LOA/Type, *[local-name() = 'F01_' || $month-names[xs:integer(format-date($date, '[F1]', 'en', (), ()))]]" separator=";"/>
<xsl:text>
</xsl:text>
<xsl:variable name="next-date" select="($date + xs:dayTimeDuration('P1D'))[. le $last-date]"/>
<xsl:apply-templates select=".[exists($next-date)]" mode="date">
<xsl:with-param name="date" select="$next-date"/>
<xsl:with-param name="last-date" select="$last-date"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Example at https://xsltfiddle.liberty-development.net/nc4NzRr/1. For XSLT 2 you could need to replace the use of the ||
string concatenation operator with calls to the concat
function: http://xsltransform.hikmatu.com/nc4NzPV.
answered 2 days ago
Martin Honnen
110k65876
110k65876
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418738%2fget-list-of-dates-based-on-condition-xslt-2-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What do you have so far?
– michael.hor257k
Nov 21 at 20:15