无法在包含元素的子元素之后创建属性节点

时间:2016-09-19 14:00:35

标签: xslt

输入xml: -

    <request version="1" type="PrintFPDPackInput">

    <keys>
<key name="OrganUnitID" value="07" />
<key name="PSIId" value="PRINT_DETAILS" />
<key name="PSILogclProcgDT" value="20.07.2016" />
<key name="PSIVrsnNo" value="1.0" />
<key name="sysId" value="GN" />
<key name="userID" value="UKLD_ZCSAdmin1" />

<key name="order_type" value="FPDT" />
<key name="archive_ind" value="Y" />
<key name="print_only" value="N" />
<key name="case_id" value="UKL_000001240009" />

<key name="calling_app" value="FileNet" />
<key name="pol_no" value="P17102-001-001" />
<key name="prod_nme" value="DL" />
<key name="bus_func_name" value="FPDT" />

<key name="log_brnd_typ_cde" value="07" />
<key name="sys_id" value="PUL" />
<key name="transfer" value="N" />
<key name="fax_ind" value="N" />
<key name="customer_type" value="Client" />
<key name="transfer_type" value="None" />
<key name="number_illustrations" value="0" />

<key name="source_system_code" value="Pulsar" />

<key name="PSIId" value="PULSAR_DETAILS" />
<key name="PSIVrsnNo" value="1.0" />
<key name="OrganUnitID" value="AD" />
<key name="sysId" value="PUL" />
<key name="Indicator" value="0" />

    </keys>
</request> 

$我的XSLT代码: -

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <!--<xsl:param name="User"/>
    <xsl:param name="Password"/> -->

    <xsl:template match="/">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"            
            xmlns:fpd="http://zip.uk.zurich.com/fpdservice">

    <soapenv:Header/>

            <soapenv:Body>



                <fpd:PrintFPDPackInput>

                    <xsl:element name="ZDOC">

                        <xsl:for-each select="request/keys/key">

                        <xsl:if test="@name = 'OrganUnitID'">
                        <xsl:attribute name="OrganUnitID"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        <xsl:if test="@name = 'PSIId'">
                        <xsl:attribute name="PSIId"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        <xsl:if test="@name = 'PSILogclProcgDT'">
                        <xsl:attribute name="PSILogclProcgDT"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        <xsl:if test="@name = 'PSIVrsnNo'">
                        <xsl:attribute name="PSIVrsnNo"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        <xsl:if test="@name = 'sysId'">
                        <xsl:attribute name="sysId"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        <xsl:if test="@name = 'userID'">
                        <xsl:attribute name="userID"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>


                        <xsl:if test="@name = 'order_type'">
                             <xsl:element name="order_type">
                              <xsl:value-of select="@value"/>
                                </xsl:element>
                       </xsl:if>
                        <xsl:if test="@name = 'archive_ind'">
                            <xsl:element name="archive_ind">
                            <xsl:value-of select="@value"/>
                            </xsl:element>
                        </xsl:if>
                        <xsl:if test="@name = 'print_only'">
                            <xsl:element name="print_only">
                            <xsl:value-of select="@value"/>
                            </xsl:element>
                        </xsl:if>
                        <xsl:if test="@name = 'case_id'">
                            <xsl:element name="case_id">
                              <xsl:value-of select="@value"/>
                            </xsl:element>
                        </xsl:if>
                    </xsl:for-each> 

                        <order_gui>

                            <data>
                            <xsl:for-each select="request/keys/key">

                                <xsl:if test="@name = 'calling_app'">
                                    <xsl:element name="calling_app">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'pol_no'">
                                    <xsl:element name="pol_no">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'prod_nme'">
                                    <xsl:element name="prod_nme">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'bus_func_name'">
                                    <xsl:element name="bus_func_name">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                            </xsl:for-each> 
                                <wfl_evnt_type_lit />

                            <xsl:for-each select="request/keys/key">    
                                <xsl:if test="@name = 'log_brnd_typ_cde'">
                                    <xsl:element name="log_brnd_typ_cde">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'sys_id'">
                                    <xsl:element name="sys_id">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                            </xsl:for-each> 
                                <task_type />

                            <xsl:for-each select="request/keys/key">    
                                <xsl:if test="@name = 'transfer'">
                                    <xsl:element name="transfer">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'fax_ind'">
                                    <xsl:element name="fax_ind">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'customer_type'">
                                    <xsl:element name="customer_type">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'transfer_type'">
                                    <xsl:element name="transfer_type">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                                <xsl:if test="@name = 'number_illustrations'">
                                    <xsl:element name="number_illustrations">
                                    <xsl:value-of select="@value"/>
                                    </xsl:element>
                                </xsl:if>
                            </xsl:for-each> 

                                <letter_notes />
                                <requested_documents />
                                <address_override>
                                <company_client>
                                    <customer_reference_number />
                                    <xsl:for-each select="request/keys/key">
                                        <xsl:if test="@name = 'source_system_code'">
                                            <xsl:element name="source_system_code">
                                            <xsl:value-of select="@value"/>
                                            </xsl:element>
                                        </xsl:if>
                                    </xsl:for-each>

                                        <name />
                                        <company_contact>
                                            <name />
                                        </company_contact>
                                </company_client>
                                <address>
                                    <line_1 />
                                    <line_2 />
                                    <line_3 />
                                    <line_4 />
                                    <postcode />
                                </address>
                                </address_override>

                            </data>
                        </order_gui>


                        <pulsar>


<xsl:element name="ZDOC">

                        <xsl:for-each select="request/keys/key">

                        <xsl:if test="@name = 'PSIId'">
                        <xsl:attribute name="PSIId"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>
                        <xsl:if test="@name = 'PSIVrsnNo'">
                        <xsl:attribute name="PSIVrsnNo"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>
                        <xsl:if test="@name = 'organUnitID'">
                        <xsl:attribute name="organUnitID"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>
                        <xsl:if test="@name = 'sysId'">
                        <xsl:attribute name="sysId"><xsl:value-of select="@value"/></xsl:attribute>
                        </xsl:if>

                        </xsl:for-each>

                        <error>
                        <xsl:for-each select="request/keys/key">
                            <xsl:if test="@name = 'Indicator'">
                                <xsl:element name="Indicator">
                                    <xsl:value-of select="@value"/>
                                </xsl:element>
                            </xsl:if>
                        </xsl:for-each>
                        <message />
                        </error>
</xsl:element>  


                        </pulsar>



                    </xsl:element>


                </fpd:PrintFPDPackInput>





            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>

</xsl:stylesheet>

$我收到错误:在包含元素的子元素之后无法创建属性节点(PSIId)。最新的元素开始标记在模块的第65行输出。你能帮忙解决这个问题。

EDIT1:

以下是我的XSLT的预期输出。

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fpd="http://zip.uk.zurich.com/fpdservice">
   <soapenv:Header />
   <soapenv:Body>
      <fpd:PrintFPDPackInput>
         <ZDOC OrganUnitId="07" PSIId="PRINT_DETAILS" PSILogclProcgDT="20.07.2016" PSIVrsnNo="1.0" sysId="GN" userID="UKLD_ZCSAdmin1">
            <order_type>FPDT</order_type>
            <archive_ind>Y</archive_ind>
            <print_only>N</print_only>
            <case_id>UKL_000001240009</case_id>
            <order_gui>
               <data>
                  <calling_app>FileNet</calling_app>
                  <pol_no>P17102-001-001</pol_no>
                  <prod_nme>DL</prod_nme>
                  <bus_func_name>FPDT</bus_func_name>
                  <wfl_evnt_type_lit />
                  <log_brnd_typ_cde>07</log_brnd_typ_cde>
                  <sys_id>PUL</sys_id>
                  <task_type />
                  <transfer>N</transfer>
                  <fax_ind>N</fax_ind>
                  <customer_type>Client</customer_type>
                  <transfer_type>None</transfer_type>
                  <number_illustrations>0</number_illustrations>
                  <letter_notes />
                  <requested_documents />
                  <address_override>
                     <company_client>
                        <customer_reference_number />
                        <source_system_code>Pulsar</source_system_code>
                        <name />
                        <company_contact>
                           <name />
                        </company_contact>
                     </company_client>
                     <address>
                        <line_1 />
                        <line_2 />
                        <line_3 />
                        <line_4 />
                        <postcode />
                     </address>
                  </address_override>
               </data>
            </order_gui>
            <pulsar>
               <ZDOC PSIId="PULSAR_DETAILS" PSIVrsnNo="1.0" organUnitId="AD" sysId="PUL">
                  <error>
                     <Indicator>0</Indicator>
                     <message />
                  </error>
</ZDOC>
            </pulsar>
</ZDOC>
      </fpd:PrintFPDPackInput>
   </soapenv:Body>
</soapenv:Envelope

1 个答案:

答案 0 :(得分:0)

问题/解决方案的第一部分

  

在包含元素的子元素之后,无法创建属性节点(PSIId)。大多数receon元素开始标记在模块的第65行输出。

根据输入文档中节点的排序顺序,将使用相同的排序顺序来创建元素/属性。 [如果没有使用过程流程更改说明]。因此,您在[示例case_id]中创建了一个子节点,之后您想为PSIId创建一个属性。

首先,您必须创建所有属性,然后才能创建子节点。

第二部分

样式表的更安全和改进版本将是:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <!--<xsl:param name="User"/>
    <xsl:param name="Password"/> -->

    <xsl:template match="/">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"            
            xmlns:fpd="http://zip.uk.zurich.com/fpdservice">

            <soapenv:Header/>
            <soapenv:Body>
                <fpd:PrintFPDPackInput>
                    <ZDOC>
                        <!-- attributes -->
                        <xsl:apply-templates select="request/keys/key[@name = 'OrganUnitID' or @name = 'PSILogclProcgDT' or @name = 'PSIVrsnNo' or @name = 'sysId' or @name = 'userID'] | request/keys/key[@name = 'PSIId'][1]" />
                        <!-- childs -->
                        <xsl:apply-templates select="request/keys/key[@name = 'order_type' or @name = 'archive_ind' or @name = 'print_only']" />

                        <order_gui>
                            <data>
                                <xsl:apply-templates select="request/keys/key[@name = 'calling_app' or @name = 'pol_no' or @name = 'prod_nme' or @name = 'bus_func_name']" /> 
                                <wfl_evnt_type_lit />
                                <xsl:apply-templates select="request/keys/key[@name = 'log_brnd_typ_cde' or @name = 'sys_id']" />
                                <task_type />
                                <xsl:apply-templates select="request/keys/key[@name = 'transfer' or @name = 'fax_ind' or @name = 'customer_type' or @name = 'transfer_type' or @name = 'number_illustrations']" /> 
                                <letter_notes />
                                <requested_documents />
                                <address_override>
                                    <company_client>
                                        <customer_reference_number />
                                        <xsl:apply-templates select="request/keys/key[@name = 'source_system_code']"/>
                                        <name />
                                        <company_contact>
                                            <name />
                                        </company_contact>
                                    </company_client>
                                    <address>
                                        <line_1 />
                                        <line_2 />
                                        <line_3 />
                                        <line_4 />
                                        <postcode />
                                    </address>
                                </address_override>
                            </data>
                        </order_gui>
                        <pulsar>
                            <ZDOC>
                                <xsl:apply-templates select="request/keys/key[@name = 'PSIId'][2] | request/keys/key[@name = 'PSIVrsnNo' or @name = 'organUnitID']" />

                                <error>
                                    <xsl:apply-templates select="request/keys/key[@name = 'Indicator']" />
                                    <message />
                                </error>
                            </ZDOC> 

                        </pulsar>
                    </ZDOC>
                </fpd:PrintFPDPackInput>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>

    <xsl:template match="key[@name = 'OrganUnitID' or @name = 'PSIId' or @name = 'PSILogclProcgDT' or @name = 'PSIVrsnNo' or @name = 'sysId' or @name = 'userID']">
        <xsl:attribute name="{@name}">
            <xsl:value-of select="@value" />
        </xsl:attribute>
    </xsl:template>

    <xsl:template match="key[@name = 'order_type' or @name = 'archive_ind' or @name = 'print_only' or @name = 'calling_app' or @name = 'pol_no' or @name = 'prod_nme' or @name = 'bus_func_name' or @name = 'log_brnd_typ_cde' or @name = 'transfer' or @name = 'fax_ind' or @name = 'customer_type' or @name = 'transfer_type' or @name = 'number_illustrations' or @name = 'source_system_code' or @name = 'Indicator']">
        <xsl:element name="{@name}">
            <xsl:value-of select="@value" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

编辑:为key @name='PSIId'添加了正确结果的位置。

如果我像之前一样匹配所有内容,请自行验证。但我相信,您可以自己完成它并根据您的需要进行修复。