As a preface, I have very little knowledge of XSLT-1.0. I feel as though what I am trying to accomplish is beyond that of a beginner.
Through other members of the community here, I have been able to come up with the following stylesheet:
<xsl:stylesheet version="2.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="/LaborTaskInterface" >
<xsl:copy>
<xsl:for-each select="LaborTask/ltOverride">
<xsl:copy>
<xsl:for-each-group select="../@* | @*" group-by="name()">
<xsl:for-each select="current-group()">
<xsl:element name="{name()}{if (position() > 1) then concat('.', position()) else ''}">
<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</xsl:for-each-group>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I have scoured other posts within the community over the years and I haven't found anything that I would claim is comparable.
I do however believe that XSLT-1.0 uses Muenchian Grouping. I am not however sure of how to apply that to the above stylesheet.
I have this XSLT-1.0 which converts the included XML(seen below) from attribute-centric to element-centric:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*" >
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I believe through applying the Muenchian method, I may be able to imitate what the XSLT-2.0 above is doing, I am just unaware of how to apply it.
What would be my key in the following:
<?xml version="1.0" encoding="UTF-8"?>
<LaborTaskInterface>
<LaborTask thing1="a" thing2="c" thing3="d" thing4="e" thing5="f"
thing6="g" thing7="h" thing8="i" thing9="j">
<ltOverride unit_id="1" value="1" thing2="k" thing3="c" thing4="d" thing10="o"/>
<ltOverride unit_id="2" value="1" thing2="l" thing3="c" thing4="d" thing11="p"/>
<ltOverride unit_id="3" value="1" thing2="m" thing3="c" thing4="d" thing12="q"/>
<ltOverride unit_id="4" value="1" thing2="n" thing3="c" thing4="d" thing13="r"/>
</LaborTask>
</LaborTaskInterface>
When applying the XSLT-1.0 above to my XML, I get the following:
<LaborTaskInterface>
<LaborTask>
<thing1>a</thing1>
<thing2>c</thing2>
<thing3>d</thing3>
<thing4>e</thing4>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<ltOverride>
<unit_id>1</unit_id>
<value>1</value>
<thing2>k</thing2>
<thing3>c</thing3>
<thing4>d</thing4>
<thing10>o</thing10>
</ltOverride>
<ltOverride>
<unit_id>2</unit_id>
<value>1</value>
<thing2>l</thing2>
<thing3>c</thing3>
<thing4>d</thing4>
<thing11>p</thing11>
</ltOverride>
<ltOverride>
<unit_id>3</unit_id>
<value>1</value>
<thing2>m</thing2>
<thing3>c</thing3>
<thing4>d</thing4>
<thing12>q</thing12>
</ltOverride>
<ltOverride>
<unit_id>4</unit_id>
<value>1</value>
<thing2>n</thing2>
<thing3>c</thing3>
<thing4>d</thing4>
<thing13>r</thing13>
</ltOverride>
</LaborTask>
</LaborTaskInterface>
As you can see, my LaborTask is not repeated with each ItOverride and the "empty" nodes are not represented within each of instance of LaborTask or ItOverride.
Can someone assist in explaining the inputs of the Muenchian Grouping method and assist me in understanding the differences to the above stylesheet that I may need to apply to achieve the conversion of this stylesheet to XSLT-1.0 or how to marry my XSLT-1.0 with the included above XSLT-2.0?
Edit, I have further attempted to utilize Muenchian Method
<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="thing1_value" match="ItOverride" use="@thing1" />
<xsl:template match="LaborTask">
<AllLaborTask>
<xsl:apply-templates select="ItOverride[generate-id(.)=generate-id(key('thing1',@thing1)[1])]"/>
</AllLaborTask>
</xsl:template>
<xsl:template match="ItOverride">
<xsl:for-each select="key('task_id', @task_id)">
<ItOverride>
<thing1><xsl:value-of select="@thing1" /></thing1>
<unit_id><xsl:value-of select="@unit_id" /></unit_id>
<thing2><xsl:value-of select="@thing2" /></thing2>
<value><xsl:value-of select="@value" /></value>
<thing3><xsl:value-of select="@thing3" /></thing3>
<thing4><xsl:value-of select="@thing4" /></thing4>
<thing5><xsl:value-of select="@thing5" /></thing5>
<thing6><xsl:value-of select="@thing6" /></thing6>
<thing7><xsl:value-of select="@thing7" /></thing7>
<thing8><xsl:value-of select="@thing8" /></thing8>
<thing9><xsl:value-of select="@thing9" /></thing9>
<thing10><xsl:value-of select="@thing10" /></thing10>
<thing11><xsl:value-of select="@thing11" /></thing11>
<thing12><xsl:value-of select="@thing12" /></thing12>
<thing13><xsl:value-of select="@thing13" /></thing13>
</ItOverride>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This is the output that the above provides:
<AllLaborTask/>
For my full XML (in which I have more than one LaborTask, it just repeats in this manner:
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
<AllLaborTask/>
Any and all help is greatly appreciated! TYIA!
When running this XSLT with the msxml edits, I am getting an error in both Access and the online converter tool I am using to debug:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxml">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="group" match="ltOverride/*" use="concat(generate-id(..), '|', name())"/>
<xsl:template match="LaborTask">
<xsl:variable name="temp-data">
<xsl:apply-templates select="ltOverride" mode="attributes-to-elements"/>
</xsl:variable>
<xsl:for-each select="mxsxml:node-set($temp-data)/ltOverride">
<xsl:copy>
<xsl:for-each select="*[generate-id() = generate-id(key('group', concat(generate-id(..), '|', name()))[1])]">
<xsl:for-each select="key('group', concat(generate-id(..), '|', name()))">
<xsl:variable name="index">
<xsl:if test="position() > 1">
<xsl:value-of select="concat('.', position())"/>
</xsl:if>
</xsl:variable>
<xsl:element name="{name()}{$index}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:template>
<xsl:template match="ltOverride" mode="attributes-to-elements">
<xsl:copy>
<xsl:apply-templates select="../@* | @*" mode="attributes-to-elements"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*" mode="attributes-to-elements">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>