如何将空字段添加到前面的同级元素,而后续元素确实有值?参见示例
我有以下 XML:
<?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>
<LaborTask thing1="aa" thing2="bb" thing3="dd" thing4="ee" thing5="ff"
thing6="gg" thing7="hh" thing8="ii" thing9="jj">
<ltOverride unit_id="11" value="11" thing2="kk" thing3="cc" thing4="dd" thing10="oo"/>
<ltOverride unit_id="22" value="12" thing2="ll" thing3="cc" thing4="dd" thing11="pp"/>
<ltOverride unit_id="33" value="13" thing2="mm" thing3="cc" thing4="dd" thing12="qq"/>
<ltOverride unit_id="44" value="14" thing2="nn" thing3="cc" thing4="dd" thing13="rr"/>
</LaborTask>
</LaborTaskInterface>
我目前已经能够使用以下 XSLT-1.0 将其转换并导入到 Microsoft Access 中:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<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="msxsl: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>
这提供了以下输出:
<LaborTaskInterface>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>k</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing10>o</thing10>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>l</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing11>p</thing11>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>m</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing12>q</thing12>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>n</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>kk</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing10>oo</thing10>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>ll</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing11>pp</thing11>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>mm</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing12>qq</thing12>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>nn</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
我想要以下输出(请注意 ItOverride 的所有实例中 thing10 - thing13 是如何存在的,每个实例都为各自的“thingXX”填充了值,但对于不存在的值则为 null。另外,为了简单起见、 aa 和 bb 代表全新的值,而不是 2xa 等):
<LaborTaskInterface>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>k</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing10>o</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>l</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing10></thing10>
<thing11>p</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>m</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing10></thing10>
<thing11></thing11>
<thing12>q</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>n</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>kk</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing10>oo</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>ll</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing10></thing10>
<thing11>pp</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>mm</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing10></thing10>
<thing11></thing11>
<thing12>qq</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>nn</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
上面的输出可以实现吗?
我认为这将涉及对 XSLT 以下部分的编辑:
<xsl:template match="LaborTask">
<xsl:variable name="temp-data">
<xsl:apply-templates select="ltOverride" mode="attributes-to-elements"/>
</xsl:variable>
<xsl:for-each select="msxsl: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>
除了可行性之外,当转换超出 XML 中的先前点时,是否有一种方法可以添加/更改先前的点?
顺便说一句,我已经使用以下链接的指导实现了对 Access 的导入: https://learn.microsoft.com/ en-us/office/troubleshoot/access/import-attribute-centric-xml
针对上面更新的 xml 运行下面建议的 xslt-1.0 后:
<LaborTaskInterface>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing2.2>k</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10>o</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing2.2>l</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11>p</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing2.2>m</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12>q</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing2.2>n</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing2.2>kk</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10>oo</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing2.2>ll</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11>pp</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing2.2>mm</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12>qq</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing2.2>nn</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
I have the following XML:
<?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>
<LaborTask thing1="aa" thing2="bb" thing3="dd" thing4="ee" thing5="ff"
thing6="gg" thing7="hh" thing8="ii" thing9="jj">
<ltOverride unit_id="11" value="11" thing2="kk" thing3="cc" thing4="dd" thing10="oo"/>
<ltOverride unit_id="22" value="12" thing2="ll" thing3="cc" thing4="dd" thing11="pp"/>
<ltOverride unit_id="33" value="13" thing2="mm" thing3="cc" thing4="dd" thing12="qq"/>
<ltOverride unit_id="44" value="14" thing2="nn" thing3="cc" thing4="dd" thing13="rr"/>
</LaborTask>
</LaborTaskInterface>
I have currently been able to transform and import this into Microsoft Access using the following XSLT-1.0:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<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="msxsl: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>
This provides the following output:
<LaborTaskInterface>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>k</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing10>o</thing10>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>l</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing11>p</thing11>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>m</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing12>q</thing12>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>n</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>kk</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing10>oo</thing10>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>ll</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing11>pp</thing11>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>mm</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing12>qq</thing12>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>nn</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
I would like the following output (note how thing10 - thing13 exist for all instances of ItOverride, each instance has the value filled for the respective "thingXX" but null for the non-existent values. Also, for the sake of simplicity, aa and bb . . . xx represent completely new values, not 2xa etc):
<LaborTaskInterface>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>k</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing10>o</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>l</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing10></thing10>
<thing11>p</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>m</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing10></thing10>
<thing11></thing11>
<thing12>q</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>a</thing1>
<thing2>c</thing2>
<thing2.2>n</thing2.2>
<thing3>d</thing3>
<thing3.2>c</thing3.2>
<thing4>e</thing4>
<thing4.2>d</thing4.2>
<thing5>f</thing5>
<thing6>g</thing6>
<thing7>h</thing7>
<thing8>i</thing8>
<thing9>j</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>kk</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing10>oo</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>ll</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing10></thing10>
<thing11>pp</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>mm</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing10></thing10>
<thing11></thing11>
<thing12>qq</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing2.2>nn</thing2.2>
<thing3>dd</thing3>
<thing3.2>cc</thing3.2>
<thing4>ee</thing4>
<thing4.2>dd</thing4.2>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
Is the above output possible to achieve?
I am thinking that it will involve an edit in the following portion of the XSLT:
<xsl:template match="LaborTask">
<xsl:variable name="temp-data">
<xsl:apply-templates select="ltOverride" mode="attributes-to-elements"/>
</xsl:variable>
<xsl:for-each select="msxsl: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>
Aside from feasbility, is there a method to add/change a prior point within an XML when the transform is beyond said point?
As a side note, I have achieved the import to Access using the following link's guidance:
https://learn.microsoft.com/en-us/office/troubleshoot/access/import-attribute-centric-xml
After running the suggested xslt-1.0 below against the updated xml above:
<LaborTaskInterface>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>1</unit_id>
<value>1</value>
<thing2.2>k</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10>o</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>2</unit_id>
<value>1</value>
<thing2.2>l</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11>p</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>3</unit_id>
<value>1</value>
<thing2.2>m</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12>q</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>4</unit_id>
<value>1</value>
<thing2.2>n</thing2.2>
<thing3.2>c</thing3.2>
<thing4.2>d</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>r</thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>11</unit_id>
<value>11</value>
<thing2.2>kk</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10>oo</thing10>
<thing11></thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>22</unit_id>
<value>12</value>
<thing2.2>ll</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11>pp</thing11>
<thing12></thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>33</unit_id>
<value>13</value>
<thing2.2>mm</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12>qq</thing12>
<thing13></thing13>
</ltOverride>
<ltOverride>
<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>
<thing1>aa</thing1>
<thing2>bb</thing2>
<thing3>dd</thing3>
<thing4>ee</thing4>
<thing5>ff</thing5>
<thing6>gg</thing6>
<thing7>hh</thing7>
<thing8>ii</thing8>
<thing9>jj</thing9>
<unit_id>44</unit_id>
<value>14</value>
<thing2.2>nn</thing2.2>
<thing3.2>cc</thing3.2>
<thing4.2>dd</thing4.2>
<thing10></thing10>
<thing11></thing11>
<thing12></thing12>
<thing13>rr</thing13>
</ltOverride>
</LaborTaskInterface>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信你必须彻底改变你的方法。也许是这样的:
XSLT 1.0
AFAICT 结果与预期输出相同,除了表示列的元素的顺序之外。
演示:https://xsltfiddle.liberty-development.net/eiorv1Z
I believe you will have to make a radical change to your approach. Maybe something like this:
XSLT 1.0
AFAICT the result is identical to the expected output, except for the order of elements representing the columns.
Demo: https://xsltfiddle.liberty-development.net/eiorv1Z