首先,我在这里花了很多时间,并且经常在这里得到已经给出的答案的帮助。但是现在我面临一个新的话题——XSLT——我现在真的需要帮助。
好的,我遇到的问题是将我从 Excel 收到的 XML 文件转换为在 XFA 表单中重用它。Excel 仅支持平面数据,但这与我的 XFA 表单的日期层次结构不匹配。
这是我从 Excel 收到的数据:
<Accounts>
    <Account Category="001" Region="AAA" Name="dolor" Value="123" Type="A" Rating="1,25"/>
    <Account Category="001" Region="AAA" Name="sit amet" Value="134" Type="A" Rating="1,25"/>
    <Account Category="004" Region="BBB" Name="consetetur" Value="434" Type="A" Rating="1,25"/>
    <Account Category="002" Region="AAA" Name="sadipscing" Value="84" Type="A" Rating="1,25"/>
    <Account Category="007" Region="ZZZ" Name="elitr" Value="33" Type="A" Rating="1,25"/>
    <Account Category="004" Region="CCC" Name="aliquyam" Value="6" Type="A" Rating="1,25"/>
    <Account Category="001" Region="BBB" Name="ipsum" Value="34" Type="A" Rating="1,25"/>
    <Account Category="003" Region="ZZZ" Name="lorem" Value="75" Type="A" Rating="2.87"/>
</Accounts>
这就是我想要改造它的方式:
<Accounts>
    <Category name="001">
        <Region name="AAA">
            <Account Name="dolor" Value="123" Type="A" Rating="1,25"/>
            <Account Name="sit amet" Value="134" Type="A" Rating="1,25"/>
        </Region>   
        <Region name="BBB">
            <Account Name="ipsum" Value="34" Type="A" Rating="1,25"/>
        </Region>
    </Category>
    <Category name="002">
        <Region name="BBB">
            <Account Name="sadipscing" Value="84" Type="A" Rating="1,25"/>
        </Region>
    </Category>
    <Category name="003">
        <Region name="ZZZ">
            <Account Name="lorem" Value="75" Type="A" Rating="2.87"/>
        </Region>
    </Category>
    ...
</Accounts>
我已经花了几天时间,但我唯一能做的就是为类别创建没有重复的新标签。这是我当前的 XSLT 文件。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" />
<xsl:variable name="Root" select="Accounts" />
<xsl:variable name="CategoryList" select="$Root/Account[not(@Category=following::Account/@Category)]" />
<xsl:template match="/">
    <Accounts>
        <xsl:for-each select="$CategoryList">
            <xsl:variable name="varCategory" select="./@Category" />
            <Category>
                <xsl:value-of select="$varCategory"/>
            </Category>
        </xsl:for-each>
    </Accounts>
</xsl:template>
</xsl:stylesheet>
欢迎任何帮助。