Get list of dates based on condition 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
add a comment |
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 '18 at 20:15
add a comment |
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 Nov 22 '18 at 7:30
Carla
asked Nov 21 '18 at 18:48
CarlaCarla
416
416
1
What do you have so far?
– michael.hor257k
Nov 21 '18 at 20:15
add a comment |
1
What do you have so far?
– michael.hor257k
Nov 21 '18 at 20:15
1
1
What do you have so far?
– michael.hor257k
Nov 21 '18 at 20:15
What do you have so far?
– michael.hor257k
Nov 21 '18 at 20:15
add a comment |
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 Nov 22 '18 at 8:02
Martin HonnenMartin Honnen
112k66177
112k66177
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 at 20:15