xml - Argument of Substring -
i have xml:
<?xml version="1.0" encoding="utf-8"?> <pi:pee xmlns:pi="urn:com.workday/picof"> <pi:employee> <pi:name>name one</pi:name> <pi:additional_information> <pi:strike_1>2017-sept.-14,8 hours=9570</pi:strike_1> <pi:strike_2>2017-sept.-11,8 hours=9570</pi:strike_2> </pi:additional_information> </pi:employee> <pi:employee> <pi:name>name two</pi:name> <pi:additional_information> <pi:strike_1>2017-sept.-10,8 hours=9570</pi:strike_1> </pi:additional_information> </pi:employee> </pi:pee>
and xslt:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs" xmlns:pi="urn:com.workday/picof" version="2.0"> <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/> <xsl:variable name="s1" select="/pi:pee/pi:employee/pi:additional_information/pi:strike_1"/> <xsl:variable name="s2" select="/pi:pee/pi:employee/pi:additional_information/pi:strike_2"/> <xsl:template name="header"> <xsl:copy-of select="."/> </xsl:template> <!-- copy data --> <xsl:template match="@* | node()" mode="#all"> <xsl:copy> <xsl:apply-templates select="@* | node()" mode="#current"/> </xsl:copy> </xsl:template> <!-- manipulation of additional information --> <xsl:template match="pi:pee/pi:employee/pi:additional_information"> <xsl:for-each select="pi:strike_1"> <pi:time_off> <pi:code_name>unpaid time off</pi:code_name> <pi:time_off_type><xsl:value-of select="substring-after($s1,'=')"/></pi:time_off_type> <pi:time_off_date><xsl:value-of select="substring-before($s1,',')"/></pi:time_off_date> <pi:quantity><xsl:value-of select="substring-before(substring-after($s1,','),' ')"/></pi:quantity> <pi:unit_of_time><xsl:value-of select="substring-after(substring-before($s1,'='),' ')"/></pi:unit_of_time> </pi:time_off> </xsl:for-each> <xsl:for-each select="pi:strike_2"> <pi:time_off> <pi:code_name>unpaid time off</pi:code_name> <pi:time_off_type><xsl:value-of select="substring-after($s2,'=')"/></pi:time_off_type> <pi:time_off_date><xsl:value-of select="substring-before($s2,',')"/></pi:time_off_date> <pi:quantity><xsl:value-of select="substring-before(substring-after($s2,','),' ')"/></pi:quantity> <pi:unit_of_time><xsl:value-of select="substring-after(substring-before($s2,'='),' ')"/></pi:unit_of_time> </pi:time_off> </xsl:for-each> </xsl:template>
the problem that, i'm getting error saying: a sequence of more 1 item not allowed first argument of substring.
what happens strings fall on pi:strike_1 come together. should process each employee, doesn't happen. while pi:strike_2 process since second employee has pi:strike_2.
my desired result is:
<pi:pee xmlns:pi="urn:com.workday/picof"> <pi:employee> <pi:name>name one</pi:name> <pi:time_off> <pi:code_name>unpaid time off</pi:code_name> <pi:time_off_type>9570</pi:time_off_type> <pi:time_off_date>2017-09-14</pi:time_off_date> <pi:quantity>8</pi:quantity> <pi:unit_of_time>hours</pi:unit_of_time> </pi:time_off> <pi:time_off> <pi:code_name>unpaid time off</pi:code_name> <pi:time_off_type>9570</pi:time_off_type> <pi:time_off_date>2017-09-11</pi:time_off_date> <pi:quantity>8</pi:quantity> <pi:unit_of_time>hours</pi:unit_of_time> </pi:time_off> </pi:employee> <pi:employee> <pi:name>name two</pi:name> <pi:time_off> <pi:code_name>unpaid time off</pi:code_name> <pi:time_off_type>9570</pi:time_off_type> <pi:time_off_date>2017-09-10</pi:time_off_date> <pi:quantity>8</pi:quantity> <pi:unit_of_time>hours</pi:unit_of_time> </pi:time_off> <pi:time_off> </pi:employee> </pi:pee>
how can resolve one? should make code work? many thanks!
Comments
Post a Comment