I have done few calculations using key-match for each line and i am expecting to sum the total of these values at the last row.
Below is the calculation.
LINE#1
4 (DispatchQuantity = 2; occurrence = 2 -> 2 x 2 = 4) MID-LAYER 12 (UnitNetWeight = 3KG x 12)
4 (DispatchQuantity = 2; occurrence = 2 -> 2 x 2 = 4) PALLET-LAYER 12 (UnitNetWeight = 3KG x 12)
LINE#2
8 (DispatchQuantity = 4; occurrence = 2 -> 4 x 2 = 8) MID-LAYER 24 (UnitNetWeight = 3KG x 8)
I need to add the numbers of each line to produce one last block which should contains 16 (4+4+8) and 48(12+12+24)
current o/p:
4 MID-LAYER 12
4 PALLET-LAYER 12
8 MID-LAYER 24
XML:
<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="16314uu19eii6-765h52u1pp0.162.97.178" timestamp="2021-10-06T02:54:24-07:00" version="1.2.051" xml:lang="en-PL">
<Header>
<Line>
<Items>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>One</Code>
<CodeIdentifier>MID-LAYER</CodeIdentifier>
<DispatchQuantity quantity="2.0"/>
</Item>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>MID-LAYER</CodeIdentifier>
<DispatchQuantity quantity="2.0"/>
</Item>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>MID-LAYER</CodeIdentifier>
<DispatchQuantity quantity="2.0"/>
</Item>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>PALLET-LAYER</CodeIdentifier>
<DispatchQuantity quantity="2.0"/>
</Item>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>PALLET-LAYER</CodeIdentifier>
<DispatchQuantity quantity="2.0"/>
</Item>
</Items>
<Items>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>MID-LAYER</CodeIdentifier>
<DispatchQuantity quantity="4.0"/>
</Item>
<Item>
<Dimension type="unitNetWeight" quantity="3.0"/>
<Code>auxiliary</Code>
<CodeIdentifier>MID-LAYER</CodeIdentifier>
<DispatchQuantity quantity="4.0"/>
</Item>
</Items>
</Line>
</Header>
</cXML>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date"
>
<!--unique key-->
<xsl:key name="aux" match="Item[Code='auxiliary']" use="concat(CodeIdentifier, '|', generate-id(..))"/>
<xsl:decimal-format name="generalFormat" grouping-separator="," decimal-separator="." />
<xsl:output method="xml" indent="yes" />
<xsl:template match="/" name="Barcode">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="ManufacturLabelSize-first" page-height="297mm" page-width="210mm" margin-top="25.4mm" margin-right="25.4mm" margin-left="25.4mm" margin-bottom="25.4mm">
<fo:region-body margin-top="15mm" />
<fo:region-before />
<fo:region-after />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="ManufacturLabelSize-first" id="pSeqID">
<fo:flow flow-name="xsl-region-body">
<fo:table>
<fo:table-body border="solid" border-width="0.5pt">
<xsl:for-each select="cXML/Header/Line">
<xsl:for-each select="Items">
<fo:table-row>
<fo:table-cell>
<!--DispatchQuantity*occurence-->
<fo:block>
<xsl:for-each select="Item[Code='auxiliary'][count(. | key('aux', concat(CodeIdentifier, '|', generate-id(..)))[1]) = 1]">
<fo:block >
<xsl:value-of select="(DispatchQuantity/#quantity) * count(key('aux', concat(CodeIdentifier, '|', generate-id(..))))"/>
</fo:block>
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<!--unique code-->
<fo:block>
<xsl:for-each select="Item[Code='auxiliary'][count(. | key('aux', concat(CodeIdentifier, '|', generate-id(..)))[1]) = 1]">
<fo:block >
<xsl:value-of select="CodeIdentifier"/>
</fo:block>
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<!--(DispatchQuantity*occurence)*UnitNetWeight-->
<fo:block>
<xsl:for-each select="Item[Code='auxiliary'][count(. | key('aux', concat(CodeIdentifier, '|', generate-id(..)))[1]) = 1]">
<fo:block font-size="8" font-family="Calibri" padding-before="2mm" start-indent="0.75mm">
<xsl:value-of select="(DispatchQuantity/#quantity) * count(key('aux', concat(CodeIdentifier, '|', generate-id(..)))) * Dimension[#type='unitNetWeight']/#quantity"/>
</fo:block>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
Your kind help is much valued!
Consider this simplified example:
XSLT 1.0 (+EXSLT node-set() function)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:key name="aux" match="Item[Code='auxiliary']" use="concat(CodeIdentifier, '|', generate-id(..))"/>
<xsl:template match="cXML">
<xsl:variable name="groups-RTF">
<xsl:for-each select="//Item[Code='auxiliary'][count(. | key('aux', concat(CodeIdentifier, '|', generate-id(..)))[1]) = 1]">
<group code="{CodeIdentifier}">
<xsl:variable name="group-size" select="count(key('aux', concat(CodeIdentifier, '|', generate-id(..))))"/>
<xsl:variable name="quantity" select="DispatchQuantity/#quantity * $group-size"/>
<quantity>
<xsl:value-of select="$quantity"/>
</quantity>
<weight>
<xsl:value-of select="Dimension[#type='unitNetWeight']/#quantity * $quantity"/>
</weight>
</group>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="groups" select="exsl:node-set($groups-RTF)/group" />
<!-- output -->
<xsl:text>code, quantity, weight
</xsl:text>
<xsl:for-each select="$groups">
<xsl:value-of select="#code"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="quantity"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="weight"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>TOTAL, </xsl:text>
<xsl:value-of select="sum($groups/quantity)"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="sum($groups/weight)"/>
</xsl:template>
</xsl:stylesheet>
Result
code, quantity, weight
MID-LAYER, 4, 12
PALLET-LAYER, 4, 12
MID-LAYER, 8, 24
TOTAL, 16, 48
Related
I'm familiar with simple muenchian grouping in XSL, but I've encountered a problem, which I honestly don't even know, how to approach it.
So I've got an XML:
<whiskies>
<whisky name="ABC" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="70" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="DEF" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="0" date=""/>
<bottle price="" size="" level="100" date=""/>
</bottles>
<comments/>
</whisky>
<whisky name="GHI" percent="" region="" type="">
<tastingNotesCollection/>
<bottles>
<bottle price="" size="" level="30" date=""/>
</bottles>
<comments/>
</whisky>
<whiskies>
And the goal is to group the whiskies by levels of a bottle:
So level="0" is considered empty.
Anything from level="1" to level="99" is considered open.
And level="100" is considered unopened.
So the transformed result (will be done in HTML) should look like this:
<h1>Empty</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
<h1>Open</h1>
<ul>
<li>ABC</li>
<li>GHI</li>
</ul>
<h1>Unopened</h1>
<ul>
<li>ABC</li>
<li>DEF</li>
</ul>
As you can see, the same whisky can show up in multiple groups, depending on how much bottles there are and how full those bottles are.
The second problem is, that the "Open" group doesn't have an exact value and can be aynthing from 1 to 99.
So yeah, don't really know if this can be solved at all or how to even start on this. Any tips appreciated.
I don't think you want to use Muenchian grouping for this. You would need to define a key that enumerates all values in the range from 1 to 99 - and I believe that would take away any advantage that using a key would otherwise bring.
Since your result has either exactly or at most 3 groups (your question is ambiguous in this respect), you could do simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="whisky[bottles/bottle/#level=0]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="whisky[bottles/bottle[#level>0 and #level < 100]]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="whisky[bottles/bottle/#level=100]">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
to get (after fixing the input to be a well-formed XML!):
Result
<?xml version="1.0" encoding="utf-8"?>
<output>
<group status="empty">
<name>ABC</name>
<name>DEF</name>
</group>
<group status="open">
<name>ABC</name>
<name>GHI</name>
</group>
<group status="unopened">
<name>ABC</name>
<name>DEF</name>
</group>
</output>
Make your own adjustment for HTML output.
Added:
Here is an alternative approach using keys (though still not Muenchian grouping) which might be more performant:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="w" match="whisky" use="bottles/bottle/#level" />
<xsl:key name="w1" match="whisky" use="boolean(bottles/bottle[#level!=0 and #level!=100])" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('w', 0)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('w1', true())">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('w', 100)">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
Or even:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:key name="bottle" match="bottle" use="ceiling(#level div 99)" />
<xsl:template match="/whiskies">
<output>
<group status="empty">
<xsl:for-each select="key('bottle', 0)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="open">
<xsl:for-each select="key('bottle', 1)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
<group status="unopened">
<xsl:for-each select="key('bottle', 2)/../..">
<name>
<xsl:value-of select="#name"/>
</name>
</xsl:for-each>
</group>
</output>
</xsl:template>
</xsl:stylesheet>
If you did want to use xsl:key, you could create 3 of them with the filter criteria:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:key name="Empty" match="whisky[bottles/bottle/#level=0]" use="#name"/>
<xsl:key name="Open" match="whisky[bottles/bottle/#level[. > 1 and . < 99]]" use="#name"/>
<xsl:key name="Unopened" match="whisky[bottles/bottle/#level=100]" use="#name"/>
<xsl:template match="/">
<xsl:variable name="whiskies" select="/whiskies/whisky/#name"/>
<xsl:for-each select="document('')/xsl:stylesheet/xsl:key/#name">
<xsl:variable name="status" select="."/>
<h1><xsl:value-of select="$status"/></h1>
<ul>
<xsl:for-each select="$whiskies[key($status, .)]">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I want to find distinct values across each node. but when i use muenchian method it will select distinct values only at top level.
Currently i am getting output as:
Bag 20
Tray 30
But i want to group type and quantity for each item
<!--for 1st item-->
Bag 20
Tray 30
<!--for 2nd item-->
Bag 20
Box 20
Tray 30
I am doing some research to make it work but did not succeed.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Items>
<Item>
<name>A</name>
<type>Bag</type>
<input quantity="20"/>
</Item>
<Item>
<name>A</name>
<type>Bag</type>
<input quantity="20"/>
</Item>
<Item>
<name>B</name>
<type>Metal</type>
<input quantity="20"/>
</Item>
<Item>
<name>A</name>
<type>Tray</type>
<input quantity="30"/>
</Item>
</Items>
<Items>
<Item>
<name>A</name>
<type>Bag</type>
<input quantity="20"/>
</Item>
<Item>
<name>A</name>
<type>Box</type>
<input quantity="20"/>
</Item>
<Item>
<name>B</name>
<type>Metal</type>
<input quantity="20"/>
</Item>
<Item>
<name>A</name>
<type>Tray</type>
<input quantity="30"/>
</Item>
</Items>
</Test>
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl"
extension-element-prefixes="date"
>
<xsl:key name="item-key" match="Items/Item[name='A']" use="input/#quantity" />
<xsl:template match="/" name="Barcode">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="ManufacturLabelSize-first" page-height="297mm" page-width="210mm" margin-top="25.4mm" margin-right="25.4mm" margin-left="25.4mm" margin-bottom="25.4mm">
<fo:region-body margin-top="15mm" />
<fo:region-before />
<fo:region-after />
</fo:simple-page-master>
<fo:simple-page-master master-name="ManufacturLabelSize-rest" page-height="297mm" page-width="210mm" margin-top="25.4mm" margin-right="25.4mm" margin-left="25.4mm" margin-bottom="25.4mm">
<fo:region-body margin-top="15mm"/>
<fo:region-before />
<fo:region-after />
</fo:simple-page-master>
<fo:page-sequence-master master-name="ManufacturLabelSize-portrait">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="ManufacturLabelSize-first"
page-position="first"/>
<fo:conditional-page-master-reference master-reference="ManufacturLabelSize-rest"
page-position="rest"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="ManufacturLabelSize-portrait" id="pSeqID">
<fo:flow flow-name="xsl-region-body">
<fo:table >
<fo:table-body border="solid" border-width="0.5pt">
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:for-each select="Test">
<xsl:for-each select="Items">
<xsl:for-each select="Item[name='A'][count(. | key('item-key',input/#quantity)[1])=1]">
<fo:block>
<xsl:value-of select="type"/> <fo:inline color="white">XXX</fo:inline><xsl:value-of select="input/#quantity"/>
</fo:block>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
Appreciate your help!
If - as it seems - you want to find distinct Items whose name is A by their type separately for each Items, then you need to include the parent Items' id in the key. Here's a simplified example:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="k" match="Item[name='A']" use="concat(type, '|', generate-id(..))"/>
<xsl:template match="/Test">
<root>
<xsl:for-each select="Items">
<xsl:comment>
<xsl:value-of select="position()" />
</xsl:comment>
<xsl:for-each select="Item[name='A'][count(. | key('k', concat(type, '|', generate-id(..)))[1]) = 1]">
<item>
<type>
<xsl:value-of select="type"/>
</type>
<quantity>
<xsl:value-of select="input/#quantity"/>
</quantity>
</item>
</xsl:for-each>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
Applied to your input example, the result will be:
Result
<?xml version="1.0" encoding="UTF-8"?>
<root>
<!--1-->
<item>
<type>Bag</type>
<quantity>20</quantity>
</item>
<item>
<type>Tray</type>
<quantity>30</quantity>
</item>
<!--2-->
<item>
<type>Bag</type>
<quantity>20</quantity>
</item>
<item>
<type>Box</type>
<quantity>20</quantity>
</item>
<item>
<type>Tray</type>
<quantity>30</quantity>
</item>
</root>
Trying to calculate day of the week number from date. Found some examples in the internet, but instead of day of the week number i see this : NaN.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="date">
<xsl:copy>
<xsl:call-template name="date-format">
<xsl:with-param name="date-time" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="date-format">
<xsl:param name="date-time"/>
<xsl:param name="date" select="substring-before($date-time,'T')"/>
<xsl:param name="year" select="substring-before($date,'-')"/>
<xsl:param name="month"
select="substring-before(substring-after($date,'-'),'-')"/>
<xsl:param name="day" select="substring-after(substring-after($date,'-'),'-')"/>
<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
<xsl:variable name="y" select="$year - $a"/>
<xsl:variable name="m" select="$month + 12 * $a - 2"/>
<xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100)
+ floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
</xsl:template>
</xsl:stylesheet>
.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="test2.xsl" type="text/xsl" ?>
<document>
<date>2013-01-01</date>
<date>2013-05-24</date>
<date>2013-12-25</date>
<date>1957-07-13</date>
<date>1776-07-04</date>
</document>
The following stylesheet:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="date">
<xsl:call-template name="day-of-week">
<xsl:with-param name="date" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="day-of-week">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date,1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
<xsl:variable name="y" select="$year + 4800 - $a"/>
<xsl:variable name="m" select="$month + 12*$a - 3"/>
<xsl:variable name="JDN" select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />
<xsl:value-of select="($JDN + 1) mod 7" />
</xsl:template>
</xsl:stylesheet>
when applied to your input example:
<document>
<date>2013-01-01</date>
<date>2013-05-24</date>
<date>2013-12-25</date>
<date>1957-07-13</date>
<date>1776-07-04</date>
</document>
will return the following result:
<?xml version="1.0" encoding="UTF-8"?>
25364
Note:
The main problem with your attempt is this:
<xsl:param name="date" select="substring-before($date-time,'T')"/>
Your input has dates, not date-times, and they do not contain "T".
I need help to count only business days (i.e excluding Saturday and Sunday ) between two dates in xslt 1.0
count only business days (i.e excluding Saturday and Sunday ) between
two dates in xslt 1.0
If it can be assumed that the two given dates will not fall on Saturday or Sunday, you could use the method shown in the following example:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<output>
<workdays>
<xsl:call-template name="duration-in-workdays">
<xsl:with-param name="start-date" select="'2015-04-02'" />
<xsl:with-param name="end-date" select="'2015-04-08'" />
</xsl:call-template>
</workdays>
</output>
</xsl:template>
<xsl:template name="duration-in-workdays">
<!-- assumes start-date and end-date are both workdays -->
<xsl:param name="start-date"/>
<xsl:param name="end-date"/>
<xsl:variable name="start">
<xsl:call-template name="JDN">
<xsl:with-param name="date" select="$start-date" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="end">
<xsl:call-template name="JDN">
<xsl:with-param name="date" select="$end-date" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="start-weekday" select="($start + 1) mod 7" />
<xsl:variable name="end-weekday" select="($end + 1) mod 7" />
<xsl:variable name="weeks" select="floor(($end - $start) div 7)" />
<xsl:variable name="days" select="($end - $start) mod 7" />
<xsl:value-of select="5 * $weeks + $days - 2*($start-weekday > $end-weekday)"/>
</xsl:template>
<xsl:template name="JDN">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
<xsl:variable name="y" select="$year + 4800 - $a"/>
<xsl:variable name="m" select="$month + 12*$a - 3"/>
<xsl:value-of select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>
Caveat: not tested thoroughly.
<xsl:template match="/">
<xsl:value-of select="this:WorkDayDifference(xs:date('2014-05-01'),xs:date('2014-05-12'))"/>
</xsl:template>
<xsl:function name="this:WorkDayDifference">
<xsl:param name="startDate" as="xs:date"/>
<xsl:param name="endDate" as="xs:date"/>
<xsl:variable name="endDateDay" select="this:day-of-week($endDate)"/>
<xsl:variable name="days" select="days-from-duration($endDate - $startDate)"/>
<xsl:variable name="dow1" select="this:day-of-week($startDate)"/>
<xsl:variable name="dow2" select="this:day-of-week($endDate)"/>
<xsl:variable name="weeks" select="xs:integer($days div 7)"/>
<xsl:variable name="offset" select="if($dow2 ge $dow1) then if($endDateDay = 6 or $endDateDay = 0)then(-6)else(-5) else if($endDateDay = 6 or $endDateDay = 0)then(-1)else(0)"/>
<xsl:variable name="wdays" select="sum((0,1,1,1,1,1,0,0,1,1,1,1,1,0)[position() ge $dow1 + 1 and position() le ($dow2 + 7)]) + $weeks * 5 + $offset + 1"/>
<xsl:value-of select="number($wdays)"/>
</xsl:function>
<xsl:function name="this:day-of-week" as="xs:integer?" >
<xsl:param name="date" as="xs:anyAtomicType?"/>
<xsl:sequence select="if (empty($date)) then () else (xs:integer((xs:date($date) - xs:date('1901-01-06')) div xs:dayTimeDuration('P1D')) mod 7)"/>
</xsl:function>
I am using the Altova mapping tool and I cannot find an option on how to eliminate a duplicate value so I am trying to update the XSLT file directly and I cannot figure out how to do this. Below is the XSLT file, the problem is in the Detail06 section.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <xsl:template match="/">
<AsyncBarcode>
<xsl:variable name="var1_instance" select="." />
<xsl:for-each select="$var1_instance/n:SyncReceiveDelivery">
<xsl:variable name="var2_SyncReceiveDelivery" select="." />
<Prefix>
<xsl:for-each select="n:DataArea/n:Sync/n:AccountingEntityID">
<CompanyID>
<xsl:value-of select="string(.)" />
</CompanyID>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:Sync/n:AccountingEntityID">
<ExternalPartnerID>
<xsl:value-of select="string(.)" />
</ExternalPartnerID>
</xsl:for-each>
<DocumentType>
<xsl:value-of select="'AsyncBarcode'" />
</DocumentType>
<xsl:for-each select="n:ApplicationArea/n:BODID">
<DocumentNumber>
<xsl:value-of select="substring-after(substring-before(string(.), ':1?'), 'Infor:')" />
</DocumentNumber>
</xsl:for-each>
<TransactionDirection>
<xsl:value-of select="'I'" />
</TransactionDirection>
<DateStamp>
<xsl:value-of select="substring-before(string(n:ApplicationArea/n:CreationDateTime), 'T')" />
</DateStamp>
<TimeStamp>
<xsl:value-of select="substring-before(substring-after(string(n:ApplicationArea/n:CreationDateTime), 'T'), 'Z')" />
</TimeStamp>
<xsl:for-each select="n:ApplicationArea/n:BODID">
<ControlNumber>
<xsl:value-of select="substring-after(substring-before(string(.), ':1?'), 'Infor:')" />
</ControlNumber>
</xsl:for-each>
</Prefix>
<Header00>
<TransactionDefinitionKey>
<xsl:value-of select="'25'" />
</TransactionDefinitionKey>
<xsl:for-each select="n:DataArea/n:Sync/n:AccountingEntityID">
<CompanyID0>
<xsl:value-of select="string(.)" />
</CompanyID0>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryHeader/n:DocumentReference/n:DocumentID">
<xsl:variable name="var14_DocumentID" select="." />
<xsl:if test="$var14_DocumentID/n:ID/#location">
<BranchID>
<xsl:value-of select="substring-before(string(n:ID/#location), '-B')" />
</BranchID>
</xsl:if>
</xsl:for-each>
<UserID>
<xsl:value-of select="'WMUser'" />
</UserID>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryHeader/n:WarehouseLocation/n:ID">
<WarehouseID>
<xsl:value-of select="substring-before(string(.), '-W')" />
</WarehouseID>
</xsl:for-each>
</Header00>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem">
<Detail01>
<xsl:for-each select="$var2_SyncReceiveDelivery/n:DataArea/n:Sync/n:AccountingEntityID">
<Scanneddata1>
<xsl:value-of select="string(.)" />
</Scanneddata1>
</xsl:for-each>
</Detail01>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery">
<xsl:variable name="var22_ReceiveDelivery" select="." />
<xsl:for-each select="n:ReceiveDeliveryItem">
<Detail02>
<xsl:for-each select="$var22_ReceiveDelivery/n:ReceiveDeliveryHeader/n:DocumentReference/n:DocumentID">
<xsl:variable name="var26_DocumentID" select="." />
<xsl:if test="$var26_DocumentID/n:ID/#location">
<Scanneddata2>
<xsl:value-of select="substring-before(string(n:ID/#location), '-B')" />
</Scanneddata2>
</xsl:if>
</xsl:for-each>
</Detail02>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery">
<xsl:variable name="var28_ReceiveDelivery" select="." />
<xsl:for-each select="n:ReceiveDeliveryItem">
<Detail03>
<xsl:for-each select="$var28_ReceiveDelivery/n:ReceiveDeliveryHeader/n:DocumentReference/n:DocumentID">
<Scanneddata3>
<xsl:value-of select="string(n:ID)" />
</Scanneddata3>
</xsl:for-each>
</Detail03>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem">
<Detail04>
<xsl:for-each select="n:LineNumber">
<Scanneddata4>
<xsl:value-of select="string(.)" />
</Scanneddata4>
</xsl:for-each>
</Detail04>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem">
<xsl:variable name="var38_ReceiveDeliveryItem" select="." />
<Detail05>
<xsl:variable name="var40_map_select_SerializedLot">
<xsl:if test="string((n:SerializedLot/n:Lot/n:LotIDs/n:ID) = (n:SerializedLot/n:Lot/n:LotIDs/n:ID)) != 'false'">
<xsl:value-of select="'1'" />
</xsl:if>
</xsl:variable>
<xsl:variable name="var48_">
<xsl:choose>
<xsl:when test="string(boolean(string($var40_map_select_SerializedLot))) != 'false'">
<xsl:variable name="var45_map_select_SerializedLot">
<xsl:for-each select="n:SerializedLot/n:Lot/n:LotIDs/n:ID">
<xsl:value-of select="string(.)" />
</xsl:for-each>
</xsl:variable>
<xsl:variable name="var41_map_select_SerializedLot">
<xsl:if test="string((string($var45_map_select_SerializedLot)) = (string($var45_map_select_SerializedLot))) != 'false'">
<xsl:value-of select="'1'" />
</xsl:if>
</xsl:variable>
<xsl:if test="string(boolean(string($var41_map_select_SerializedLot))) != 'false'">
<xsl:variable name="var42_map_select_SerializedLot">
<xsl:for-each select="n:SerializedLot/n:Lot/n:LotIDs/n:ID">
<xsl:value-of select="string(.)" />
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="string($var42_map_select_SerializedLot)" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="' '" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<Scanneddata5>
<xsl:copy-of select="$var48_" />
</Scanneddata5>
</Detail05>
</xsl:for-each>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem">
<Detail06>
<xsl:for-each select="n:HoldCodes/n:Code">
<Scanneddata6>
<xsl:choose>
<xsl:when test="string((' ' != string(.))) != 'false'">
<xsl:value-of select="'Hold'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Inventory'" />
</xsl:otherwise>
</xsl:choose>
</Scanneddata6>
</xsl:for-each>
</Detail06>
</xsl:for-each>
<Detail07>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryHeader/n:ReceivedDateTime">
<Scanneddata7>
<xsl:value-of select="string(.)" />
</Scanneddata7>
</xsl:for-each>
</Detail07>
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem">
<Detail11>
<xsl:for-each select="n:ReceivedQuantity">
<Scanneddata11>
<xsl:value-of select="number(string(.))" />
</Scanneddata11>
</xsl:for-each>
</Detail11>
</xsl:for-each>
</xsl:for-each>
</AsyncBarcode>
</xsl:template>
</xsl:stylesheet>
Below is the input I am receiving:
<SyncReceiveDelivery xmlns="http://schema.infor.com/InforOAGIS/2" releaseID="9.2" versionID="2.8.0">
<ApplicationArea>
<Sender>
<LogicalID>lid://</LogicalID>
<ComponentID>Warehouse Management</ComponentID>
<ReferenceID accountingEntity="01" location="RS01-W">0000058141</ReferenceID>
</Sender>
<CreationDateTime>2015-03-31T20:08:16Z</CreationDateTime>
<BODID>infor-nid:infor:01:RS01-W:0000002445:62883?ReceiveDelivery&verb=Sync</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor</TenantID>
<AccountingEntityID>01</AccountingEntityID>
<LocationID accountingEntity="01">RS01-W</LocationID>
<ActionCriteria>
<ActionExpression actionCode="Add" />
</ActionCriteria>
</Sync>
<ReceiveDelivery>
<ReceiveDeliveryHeader>
<DocumentID>
<ID accountingEntity="01" location="RS01-W" variationID="62883">0000002445</ID>
</DocumentID>
<LastModificationDateTime>2015-03-31T20:08:12Z</LastModificationDateTime>
<DocumentDateTime>2015-03-31T20:08:12Z</DocumentDateTime>
<DocumentReference type="CustomerReturn">
<DocumentID>
<ID accountingEntity="01" location="1323-B">930131</ID>
</DocumentID>
</DocumentReference>
<Status>
<Code listID="ReceiveDeliveryStatus">Received</Code>
</Status>
<WarehouseLocation>
<ID accountingEntity="01">RS01-W</ID>
<Name languageID="en-US">Power Packaging</Name>
<Address>
<AddressLine sequence="1">401 N. Main</AddressLine>
<CityName>Rosendale</CityName>
<CountrySubDivisionCode>WI</CountrySubDivisionCode>
<PostalCode listID="PostalCode">54974</PostalCode>
</Address>
</WarehouseLocation>
<ActualDeliveryDateTime>2015-03-31T17:31:46Z</ActualDeliveryDateTime>
<GrossWeightMeasure unitCode="LB">8120.4147</GrossWeightMeasure>
<TotalVolumeMeasure unitCode="CF">0</TotalVolumeMeasure>
<ShipFromParty>
<Location>
<ID>30155</ID>
<Name languageID="en-US">RS-IFP-USFS HOUSTON</Name>
<Address>
<AddressLine sequence="1">USFS HOUSTON</AddressLine>
<AddressLine sequence="2">111 ALIANT DRIVE</AddressLine>
<CityName>HOUSTON</CityName>
<CountrySubDivisionCode>TX</CountrySubDivisionCode>
<CountryCode>USA</CountryCode>
<PostalCode listID="PostalCode">77032</PostalCode>
</Address>
</Location>
</ShipFromParty>
<ReceivedDateTime>2015-03-31T20:08:12Z</ReceivedDateTime>
<DeliverToParty>
<Location>
<ID accountingEntity="01">RS01-W</ID>
<Name languageID="en-US">Power Packaging</Name>
<Address>
<AddressLine sequence="1">401 N. Main</AddressLine>
<CityName>Rosendale</CityName>
<CountrySubDivisionCode>WI</CountrySubDivisionCode>
<PostalCode listID="PostalCode">54974</PostalCode>
</Address>
</Location>
</DeliverToParty>
<ASNReference>
<DocumentID>
<ID accountingEntity="01" location="RS01-W">0000002445</ID>
</DocumentID>
</ASNReference>
</ReceiveDeliveryHeader>
<ReceiveDeliveryItem>
<ItemID>
<ID accountingEntity="01">200135-100250</ID>
</ItemID>
<ServiceIndicator>false</ServiceIndicator>
<Description languageID="en-US">Orchard Splash 12/25 fl oz Orange Gold 100</Description>
<Note languageID="en-US">1</Note>
<DocumentReference type="CustomerReturn">
<DocumentID>
<ID accountingEntity="01" location="1323-B">930131</ID>
</DocumentID>
<LineNumber>1</LineNumber>
</DocumentReference>
<PackingSlipQuantity unitCode="CS">0.0</PackingSlipQuantity>
<PackingSlipBaseUOMQuantity unitCode="CS">0.0</PackingSlipBaseUOMQuantity>
<ReceivedQuantity unitCode="CS">90.0</ReceivedQuantity>
<ReceivedBaseUOMQuantity unitCode="CS">90.0</ReceivedBaseUOMQuantity>
<ReturnedQuantity unitCode="CS">0.0</ReturnedQuantity>
<ReturnedBaseUOMQuantity unitCode="CS">0.0</ReturnedBaseUOMQuantity>
<SerializedLot>
<ItemQuantity unitCode="CS">90.0</ItemQuantity>
<ItemBaseUOMQuantity unitCode="CS">90.0</ItemBaseUOMQuantity>
<Lot>
<LotIDs>
<ID>RS1412107</ID>
</LotIDs>
<Quantity unitCode="CS">90.0</Quantity>
<BaseUOMQuantity unitCode="CS">90.0</BaseUOMQuantity>
</Lot>
</SerializedLot>
<LineNumber>1</LineNumber>
<HoldCodes>
<Code listID="Hold Reason Codes">HOLD</Code>
</HoldCodes>
<HoldCodes>
<Code listID="Hold Reason Codes">QCREQ</Code>
</HoldCodes>
<CountSequence>1</CountSequence>
</ReceiveDeliveryItem>
<ReceiveDeliveryItem>
<ItemID>
<ID accountingEntity="01">200135-100252</ID>
</ItemID>
<ServiceIndicator>false</ServiceIndicator>
<Description languageID="en-US">Orchard Hills 12/25 fl oz Orange 100</Description>
<Note languageID="en-US">2</Note>
<DocumentReference type="CustomerReturn">
<DocumentID>
<ID accountingEntity="01" location="1323-B">930131</ID>
</DocumentID>
<LineNumber>2</LineNumber>
</DocumentReference>
<PackingSlipQuantity unitCode="CS">0.0</PackingSlipQuantity>
<PackingSlipBaseUOMQuantity unitCode="CS">0.0</PackingSlipBaseUOMQuantity>
<ReceivedQuantity unitCode="CS">90.0</ReceivedQuantity>
<ReceivedBaseUOMQuantity unitCode="CS">90.0</ReceivedBaseUOMQuantity>
<ReturnedQuantity unitCode="CS">0.0</ReturnedQuantity>
<ReturnedBaseUOMQuantity unitCode="CS">0.0</ReturnedBaseUOMQuantity>
<SerializedLot>
<ItemQuantity unitCode="CS">90.0</ItemQuantity>
<ItemBaseUOMQuantity unitCode="CS">90.0</ItemBaseUOMQuantity>
<Lot>
<LotIDs>
<ID>RS141112</ID>
</LotIDs>
<Quantity unitCode="CS">90.0</Quantity>
<BaseUOMQuantity unitCode="CS">90.0</BaseUOMQuantity>
</Lot>
</SerializedLot>
<LineNumber>2</LineNumber>
<HoldCodes>
<Code listID="Hold Reason Codes">HOLD</Code>
</HoldCodes>
<HoldCodes>
<Code listID="Hold Reason Codes">QCREQ</Code>
</HoldCodes>
<CountSequence>1</CountSequence>
</ReceiveDeliveryItem>
<ReceiveDeliveryItem>
<ItemID>
<ID accountingEntity="01">200135-100252</ID>
</ItemID>
<ServiceIndicator>false</ServiceIndicator>
<Description languageID="en-US">Orchard Hills 12/25 fl oz Orange 100</Description>
<Note languageID="en-US">3</Note>
<DocumentReference type="CustomerReturn">
<DocumentID>
<ID accountingEntity="01" location="1323-B">930131</ID>
</DocumentID>
<LineNumber>3</LineNumber>
</DocumentReference>
<PackingSlipQuantity unitCode="CS">0.0</PackingSlipQuantity>
<PackingSlipBaseUOMQuantity unitCode="CS">0.0</PackingSlipBaseUOMQuantity>
<ReceivedQuantity unitCode="CS">90.0</ReceivedQuantity>
<ReceivedBaseUOMQuantity unitCode="CS">90.0</ReceivedBaseUOMQuantity>
<ReturnedQuantity unitCode="CS">0.0</ReturnedQuantity>
<ReturnedBaseUOMQuantity unitCode="CS">0.0</ReturnedBaseUOMQuantity>
<SerializedLot>
<ItemQuantity unitCode="CS">90.0</ItemQuantity>
<ItemBaseUOMQuantity unitCode="CS">90.0</ItemBaseUOMQuantity>
<Lot>
<LotIDs>
<ID>RS1412030</ID>
</LotIDs>
<Quantity unitCode="CS">90.0</Quantity>
<BaseUOMQuantity unitCode="CS">90.0</BaseUOMQuantity>
</Lot>
</SerializedLot>
<LineNumber>3</LineNumber>
<HoldCodes>
<Code listID="Hold Reason Codes">HOLD</Code>
</HoldCodes>
<HoldCodes>
<Code listID="Hold Reason Codes">QCREQ</Code>
</HoldCodes>
<CountSequence>1</CountSequence>
</ReceiveDeliveryItem>
</ReceiveDelivery>
</DataArea>
</SyncReceiveDelivery>
Finally, this is what I am expecting however I am getting duplicates values in Scannedata6 for the Detail06 section:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE AsyncBarcode SYSTEM "C:/InboundBODS/AsyncBarcode_Inbound.dtd">
<AsyncBarcode>
<Prefix>
<CompanyID>01</CompanyID>
<ExternalPartnerID>01</ExternalPartnerID>
<DocumentType>AsyncBarcode</DocumentType>
<DocumentNumber/>
<TransactionDirection>I</TransactionDirection>
<DateStamp>2015-03-31</DateStamp>
<TimeStamp>20:08:16</TimeStamp>
<ControlNumber/>
</Prefix>
<Header00>
<TransactionDefinitionKey>25</TransactionDefinitionKey>
<CompanyID0>01</CompanyID0>
<BranchID>1323</BranchID>
<UserID>WMUser</UserID>
<WarehouseID>RS01</WarehouseID>
</Header00>
<Detail01>
<Scanneddata1>01</Scanneddata1>
</Detail01>
<Detail01>
<Scanneddata1>01</Scanneddata1>
</Detail01>
<Detail01>
<Scanneddata1>01</Scanneddata1>
</Detail01>
<Detail02>
<Scanneddata2>1323</Scanneddata2>
</Detail02>
<Detail02>
<Scanneddata2>1323</Scanneddata2>
</Detail02>
<Detail02>
<Scanneddata2>1323</Scanneddata2>
</Detail02>
<Detail03>
<Scanneddata3>930131</Scanneddata3>
</Detail03>
<Detail03>
<Scanneddata3>930131</Scanneddata3>
</Detail03>
<Detail03>
<Scanneddata3>930131</Scanneddata3>
</Detail03>
<Detail04>
<Scanneddata4>1</Scanneddata4>
</Detail04>
<Detail04>
<Scanneddata4>2</Scanneddata4>
</Detail04>
<Detail04>
<Scanneddata4>3</Scanneddata4>
</Detail04>
<Detail05>
<Scanneddata5>RS1412107</Scanneddata5>
</Detail05>
<Detail05>
<Scanneddata5>RS141112</Scanneddata5>
</Detail05>
<Detail05>
<Scanneddata5>RS1412030</Scanneddata5>
</Detail05>
<Detail06>
<Scanneddata6>Hold</Scanneddata6>
</Detail06>
<Detail06>
<Scanneddata6>Hold</Scanneddata6>
</Detail06>
<Detail06>
<Scanneddata6>Hold</Scanneddata6>
</Detail06>
<Detail07>
<Scanneddata7>2015-03-31T20:08:12Z</Scanneddata7>
</Detail07>
<Detail11>
<Scanneddata11>90</Scanneddata11>
</Detail11>
<Detail11>
<Scanneddata11>90</Scanneddata11>
</Detail11>
<Detail11>
<Scanneddata11>90</Scanneddata11>
</Detail11>
</AsyncBarcode>
Was able to figure out what I needed to change. Change shown below:
<xsl:for-each select="n:DataArea/n:ReceiveDelivery/n:ReceiveDeliveryItem/n:HoldCodes[1]">
<Detail06>
<xsl:for-each select="n:Code[1]">
<Scanneddata6>
<xsl:choose>
<xsl:when test="string(('' != string(.))) != 'false'">
<xsl:value-of select="'Hold'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Inventory'" />
</xsl:otherwise>
</xsl:choose>
</Scanneddata6>
</xsl:for-each>
</Detail06>
</xsl:for-each>