我正在将数据从Access数据库输出到XML,准备导入我们公司使用的外国系统。导入必须以特定方式进行格式化,我正在尝试使用XSLT转换来格式化它。
这是从外国系统导入的示例;
<?xml version="1.0"?>
<tg:orders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tg="http://www.technique-group.com" xsi:schemaLocation="http://www.technique-group.com/schemas TGScheduleImport_v1.4.xsd" tg:version="1.2">
<!-- the following xml describes a 244pp perfect bound magazine with an order quantity of 176277 copies -->
<!-- There are 8 versions and all forms are versioned -->
<!-- version ONT NEWS (176,277 copies) -->
<!-- version BAL OF CAN NEWS (19,402 copies) -->
<!-- version BAL OF CAN NEWS (9,411 copies) -->
<!-- version BC NEWS (5,012 copies) -->
<!-- version QUE NEWS (3,777 copies) -->
<!-- version ONT SUBS (88,874 copies) -->
<!-- version BAL OF CAN SUBS (19,407 copies) -->
<!-- version BC SUBS (18,760 copies) -->
<!-- version QUE SUBS (11,619 copies) -->
<!-- NOTE: All quantities should be the number of good copies required from the relevant task -->
<!-- For example, for a press run, of 215,000 that requires 10,000 extra for bindery overs should have a quantity of 225,000 -->
<!-- job id must be a unique 10 character alphanumeric reference and is used to match details in a foreign system -->
<!-- site code must be a unique 2 character alphanumeric reference that is used to determine the site where the order will be produced. This must match a site code in Technique -->
<tg:order tg:job_id="SC10268" tg:site_code="SC" tg:replace="true">
<tg:job_description>STJ Import - AUG 2007</tg:job_description>
<tg:order_qty>176277</tg:order_qty>
<!-- finishing style should be WS for saddle stitched or PB for perfect bound -->
<tg:finishing_style>PB</tg:finishing_style>
<!-- overall finished trim size and extent -->
<tg:depth>8.25</tg:depth>
<tg:width>10.875</tg:width>
<tg:cover_pagination>4</tg:cover_pagination>
<tg:text_pagination>240</tg:text_pagination>
<!-- deadline dates for the job are specified here -->
<tg:delivery_commence_date>2007-11-04</tg:delivery_commence_date>
<tg:delivery_complete_date>2007-11-05</tg:delivery_complete_date>
<!-- job site and managing printer should default to your site code we set up for the trial -->
<tg:job_site>SC</tg:job_site>
<tg:managing_printer>SC</tg:managing_printer>
<!-- job site and managing printer should default to true for the trial -->
<tg:is_managing_printer>true</tg:is_managing_printer>
<!-- customer purchase order reference if known -->
<tg:cust_order_ref>776030</tg:cust_order_ref>
<!-- customer code should be a unique reference that we will use to add customer detail and avoid duplicates -->
<!-- see seperate company import specification for further company details -->
<!-- Customer code MUST match an CompanyShortCode in the Company DB -->
<tg:cust_code>Sears</tg:cust_code>
<!-- add as many job related contacts as you need -->
<tg:cust_contact tg:cust_contact_code="jill.summers@sears.com"/>
<tg:cust_contact tg:cust_contact_code="simon.caldwell@sears.com"/>
<!-- account exec / CSR details - the email address will be used as a unique key to avoid duplicates -->
<!-- we will add new CSR's (based on email address to the list of available CSR's -->
<tg:site_cce_name>Cathy Noble</tg:site_cce_name>
<tg:site_cce_phone>(847) 466 1008</tg:site_cce_phone>
<tg:site_cce_mobile>(847) 477 2008</tg:site_cce_mobile>
<tg:site_cce_email>cathy.noble@superior.com</tg:site_cce_email>
<!-- sales rep details - the email address will be used as a unique key to avoid duplicates -->
<!-- we will add new sales reps (based on email address to the list of available sales reps -->
<tg:sales_person_name>Sam Brown</tg:sales_person_name>
<tg:sales_person_phone>(847) 466 1001</tg:sales_person_phone>
<tg:sales_person_mobile>(847) 477 2001</tg:sales_person_mobile>
<tg:sales_person_email>sam.brown@superior.com</tg:sales_person_email>
<!-- master press / printed version details - there MUST always be a COMM version regardless of whether it is used -->
<!-- If no common version is printed, add the COMM version with a qty equal to sum of all version splits and set version_finished to "false" -->
<!-- version_id is an internal Technique reference and can be left empty for the import -->
<!-- WIT XML: press_version -->
<!-- These are the print versions. version_finished is false as they are WIP components -->
<!-- DUMMY Common version as there is no common component -->
<tg:master_version>
<tg:version_id/>
<tg:version_code>COMM</tg:version_code>
<tg:version_common>true</tg:version_common>
<tg:version_finished>false</tg:version_finished>
<tg:version_description>Common</tg:version_description>
<tg:version_nett_qty>176262</tg:version_nett_qty>
<tg:version_special_qty>10</tg:version_special_qty>
</tg:master_version>
<tg:press_section>
<tg:signature_id>001</tg:signature_id>
<tg:sequence_id>1</tg:sequence_id>
<tg:sequence_alpha>A</tg:sequence_alpha>
<tg:description>4ppCover</tg:description>
<tg:pagination>4</tg:pagination>
<tg:trim_size>10.875 x 8.375</tg:trim_size>
<tg:folio/>
<tg:data_format/>
<tg:data_medium/>
<tg:data_due/>
<tg:version>
<!-- task_sub_job_id's MUST be Unique system wide as will be used as part references -->
<!-- Resources, MR times, run times and press speeds need to be entered here -->
<!-- These are planned values, but may change when the job is actually scheduled -->
<!-- The values entered here will be preserved, regardless of how the job is scheduled -->
<tg:version_code>COMM</tg:version_code>
<tg:task_info tg:confirmed="true" tg:maintenance="false" tg:provisional="false">
<tg:task_sub_job_id>SC10268-001COMM</tg:task_sub_job_id>
<tg:task_seq_id>0</tg:task_seq_id>
<tg:task_description>4pp NEWS-NEWS COMM</tg:task_description>
<tg:task_qty_rqd>9636</tg:task_qty_rqd>
<tg:task_resource_id>116</tg:task_resource_id>
<tg:task_mr_mins>120</tg:task_mr_mins>
<tg:task_run_mins>240</tg:task_run_mins>
<tg:task_run_speed>18000</tg:task_run_speed>
<tg:task_notes>Task Notes</tg:task_notes>
<tg:task_no_up>4</tg:task_no_up>
<tg:task_deadline_date_time/>
<tg:task_pdt>0.0</tg:task_pdt>
</tg:task_info>
</tg:version>
</tg:press_section>
<tg:post_press_version>
<tg:post_press_version_op_id>0</tg:post_press_version_op_id>
<tg:version_code>COMM</tg:version_code>
<tg:post_press_resource_type>PB</tg:post_press_resource_type>
<tg:task_info tg:confirmed="true" tg:maintenance="false" tg:provisional="false">
<tg:task_sub_job_id>SC10268-1COMM</tg:task_sub_job_id>
<tg:task_seq_id>0</tg:task_seq_id>
<tg:task_description>Perfect Binding</tg:task_description>
<tg:task_qty_rqd>19402</tg:task_qty_rqd>
<tg:task_resource_id>130</tg:task_resource_id>
<tg:task_mr_mins>120</tg:task_mr_mins>
<tg:task_run_mins>240</tg:task_run_mins>
<tg:task_run_speed>7500</tg:task_run_speed>
<tg:task_notes>Task Notes</tg:task_notes>
<tg:task_no_up>1</tg:task_no_up>
<tg:task_deadline_date_time/>
<tg:task_pdt>0.0</tg:task_pdt>
</tg:task_info>
</tg:post_press_version>
<!-- Schedule information is required if the jobs are to bypass the To Do List and go directly to the planning board -->
<!-- Scheduel information (without start and end time/dates is also required to link tasks together in ToDo list (i.e. two streams). See example below -->
<!-- A scheduled item can include multiple tasks (e.g. multiple deliveries/ganged jobs -->
<!-- Each <schedule node> corresponds to the top half of the component details dialog in Technique Scheduling (when a task is double-clicked) -->
<!-- Each <schedule_task> node refers to a task listed elsewhere in the XML -->
<!-- This node corresponds to the bottom half of the component details dialog in Technique Scheduling (when a task is double-clicked) -->
<!-- The task_sub_job_id is the unique identifier for a task. For press runs the sub-job no is typically derived from: <Job No>-<Sig><VersCode> -->
<!-- For postpress operations the sub-job no is typically derived from: <Job No>-<WIP Part Ref> -->
<!-- Schedule Info -->
<tg:schedule>
<tg:schedule_start_date_time>2007-11-05T06:20:00</tg:schedule_start_date_time>
<tg:schedule_end_date_time>2007-11-05T12:15:00</tg:schedule_end_date_time>
<tg:schedule_multi_task_desc />
<tg:schedule_resource_id>116</tg:schedule_resource_id>
<tg:schedule_mr_mins>120</tg:schedule_mr_mins>
<tg:schedule_run_mins>450</tg:schedule_run_mins>
<tg:schedule_run_speed>30000</tg:schedule_run_speed>
<tg:schedule_no_of_staff>2</tg:schedule_no_of_staff>
<tg:task_pdt>10.0</tg:task_pdt>
<tg:schedule_crit_delay_mins>0</tg:schedule_crit_delay_mins>
<tg:schedule_locked>false</tg:schedule_locked>
<tg:schedule_task>
<tg:task_sub_job_id>SC10268-001COMM</tg:task_sub_job_id>
<tg:task_seq_id>0</tg:task_seq_id>
<tg:schedule_task_stream>1</tg:schedule_task_stream>
<tg:schedule_qty>10000</tg:schedule_qty>
</tg:schedule_task>
</tg:schedule>
<!-- Perfect Binder -->
<tg:schedule>
<tg:schedule_start_date_time>2007-11-05T12:39:00</tg:schedule_start_date_time>
<tg:schedule_end_date_time>2007-11-05T22:39:00</tg:schedule_end_date_time>
<tg:schedule_multi_task_desc />
<tg:schedule_resource_id>130</tg:schedule_resource_id>
<tg:schedule_mr_mins>120</tg:schedule_mr_mins>
<tg:schedule_run_mins>480</tg:schedule_run_mins>
<tg:schedule_run_speed>8000</tg:schedule_run_speed>
<tg:schedule_no_of_staff>4</tg:schedule_no_of_staff>
<tg:task_pdt>0.0</tg:task_pdt>
<tg:schedule_crit_delay_mins>0</tg:schedule_crit_delay_mins>
<tg:schedule_locked>false</tg:schedule_locked>
<tg:schedule_task>
<tg:task_sub_job_id>SC10268-1COMM</tg:task_sub_job_id>
<tg:task_seq_id>0</tg:task_seq_id>
<tg:schedule_task_stream>1</tg:schedule_task_stream>
<tg:schedule_qty>11619</tg:schedule_qty>
</tg:schedule_task>
</tg:schedule>
</tg:order>
</tg:orders>
我实际上只是为某些部分创建数据,因此可以忽略其中一些部分。这是在转换之前从Access输出的XML;
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2015-01-08T09:33:08">
<order>
<ORDERPK>1</ORDERPK>
<job_id>SC10268</job_id>
<site_code>SC</site_code>
<Replace>true</Replace>
<job_description>STJ Import - AUG 2007</job_description>
<order_qty>176277</order_qty>
<finishing_style>PB</finishing_style>
<depth>8.25</depth>
<width>10.875</width>
<cover_pagination>4</cover_pagination>
<text_pagination>240</text_pagination>
<delivery_commence_date>2007-11-04</delivery_commence_date>
<delivery_complete_date>2007-11-05</delivery_complete_date>
<job_site>SC</job_site>
<managing_printer>SC</managing_printer>
<is_managing_printer>true</is_managing_printer>
<cust_order_ref>776030</cust_order_ref>
<cust_code>Sears</cust_code>
<cust_contact></cust_contact>
<site_cce_name>Cathy Noble</site_cce_name>
<site_cce_phone>(847) 466 1008</site_cce_phone>
<site_cce_mobile>(847) 477 2008</site_cce_mobile>
<site_cce_email>cathy.noble@superior.com</site_cce_email>
<sales_person_name>Sam Brown</sales_person_name>
<sales_person_phone>(847) 466 1001</sales_person_phone>
<sales_person_mobile>(847) 477 2001</sales_person_mobile>
<sales_person_email>sam.brown@superior.com</sales_person_email>
</order>
<master_version>
<ORDER>1</ORDER>
<version_id></version_id>
<version_code>COMM</version_code>
<version_common>true</version_common>
<version_finished>false</version_finished>
<version_description>Common</version_description>
<version_nett_qty>176262</version_nett_qty>
<version_special_qty>10</version_special_qty>
</master_version>
<master_version>
<ORDER>2</ORDER>
<version_code>COMM</version_code>
<version_common>TRUE</version_common>
<version_finished>FALSE</version_finished>
<version_description>Common</version_description>
<version_nett_qty>1900</version_nett_qty>
<version_special_qty>0</version_special_qty>
</master_version>
<master_version>
<ORDER>3</ORDER>
<version_code>COMM</version_code>
<version_common>true</version_common>
<version_finished>false</version_finished>
<version_description>common</version_description>
<version_nett_qty>20000</version_nett_qty>
<version_special_qty>0</version_special_qty>
</master_version>
<press_section>
<ORDER>1</ORDER>
<signature_id>001</signature_id>
<sequence_id>1</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>4ppCover</description>
<pagination>4</pagination>
<trim_size>10.875 x 8.375</trim_size>
<folio></folio>
<data_format></data_format>
<data_medium></data_medium>
<data_due></data_due>
</press_section>
<press_section>
<ORDER>1</ORDER>
<signature_id>001</signature_id>
<sequence_id>2</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>240ppText</description>
<pagination>240</pagination>
<trim_size>103875 x 8.25</trim_size>
</press_section>
<press_section>
<ORDER>2</ORDER>
<signature_id>001</signature_id>
<sequence_id>1</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>4pp Cover</description>
<pagination>4</pagination>
<trim_size>10 x 8</trim_size>
</press_section>
<press_section>
<ORDER>2</ORDER>
<signature_id>001</signature_id>
<sequence_id>2</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>12pp Text</description>
<pagination>12</pagination>
<trim_size>10 x 8</trim_size>
</press_section>
<press_section>
<ORDER>3</ORDER>
<signature_id>001</signature_id>
<sequence_id>0</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>4pp Cover</description>
<pagination>4</pagination>
<trim_size>10 x 8</trim_size>
</press_section>
<press_section>
<ORDER>3</ORDER>
<signature_id>001</signature_id>
<sequence_id>1</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>24pp Text</description>
<pagination>24</pagination>
<trim_size>10 x 8</trim_size>
</press_section>
<version>
<ORDER>1</ORDER>
<version_code>COMM</version_code>
</version>
<version>
<ORDER>2</ORDER>
<version_code>COMM</version_code>
</version>
<version>
<ORDER>3</ORDER>
<version_code>COMM</version_code>
</version>
<task_info_press_section>
<ORDER>1</ORDER>
<PRESS_x0020_SECTION>1</PRESS_x0020_SECTION>
<task_sub_job_id>SC10268-001COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>4pp NEWS-NEWS COMM</task_description>
<task_qty_rqd>9636</task_qty_rqd>
<task_resource_id>1</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>18000</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>4</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info_press_section>
<task_info_press_section>
<ORDER>1</ORDER>
<PRESS_x0020_SECTION>1</PRESS_x0020_SECTION>
<task_sub_job_id>SC10268-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>19402</task_qty_rqd>
<task_resource_id>1</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>7500</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>1</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info_press_section>
<task_info_press_section>
<ORDER>2</ORDER>
<PRESS_x0020_SECTION>2</PRESS_x0020_SECTION>
<task_sub_job_id>S019191-9-001COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>4pp Cover</task_description>
<task_qty_rqd>1900</task_qty_rqd>
<task_resource_id>2</task_resource_id>
<task_mr_mins>20</task_mr_mins>
<task_run_mins>63</task_run_mins>
<task_run_speed>30</task_run_speed>
<task_no_up>4</task_no_up>
<task_pdt>0.0</task_pdt>
</task_info_press_section>
<task_info_press_section>
<ORDER>2</ORDER>
<PRESS_x0020_SECTION>2</PRESS_x0020_SECTION>
<task_sub_job_id>S019191-9-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>1900</task_qty_rqd>
<task_resource_id>2</task_resource_id>
<task_mr_mins>20</task_mr_mins>
<task_run_mins>120</task_run_mins>
<task_run_speed>240</task_run_speed>
<task_no_up>1</task_no_up>
<task_pdt>0.0</task_pdt>
</task_info_press_section>
<task_info_press_section>
<ORDER>3</ORDER>
<PRESS_x0020_SECTION>3</PRESS_x0020_SECTION>
<task_sub_job_id>S026500-1-001COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>4ppCover</task_description>
<task_qty_rqd>20000</task_qty_rqd>
<task_resource_id>2</task_resource_id>
</task_info_press_section>
<task_info_press_section>
<ORDER>3</ORDER>
<PRESS_x0020_SECTION>3</PRESS_x0020_SECTION>
<task_sub_job_id>S026500-1-1COMM</task_sub_job_id>
<task_seq_id>1</task_seq_id>
<task_description>24ppText</task_description>
<task_qty_rqd>20000</task_qty_rqd>
<task_resource_id>2</task_resource_id>
</task_info_press_section>
<task_info_post_press>
<ORDER>1</ORDER>
<POST_x0020_PRESS>1</POST_x0020_PRESS>
<task_sub_job_id>SC10268-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>19402</task_qty_rqd>
<task_resource_id>10</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>7500</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>1</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info_post_press>
<task_info_post_press>
<ORDER>2</ORDER>
<POST_x0020_PRESS>2</POST_x0020_PRESS>
<task_sub_job_id>S019191-9-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>1900</task_qty_rqd>
<task_resource_id>10</task_resource_id>
<task_mr_mins>20</task_mr_mins>
<task_run_mins>120</task_run_mins>
<task_run_speed>240</task_run_speed>
<task_no_up>1</task_no_up>
<task_pdt>0.0</task_pdt>
</task_info_post_press>
<task_info_post_press>
<ORDER>3</ORDER>
<POST_x0020_PRESS>3</POST_x0020_PRESS>
<task_sub_job_id>S026500-1-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>20000</task_qty_rqd>
<task_resource_id>10</task_resource_id>
</task_info_post_press>
<post_press_version>
<ORDER>1</ORDER>
<post_press_version_op_id>0</post_press_version_op_id>
<version_code>COMM</version_code>
<post_press_resource_type>PB</post_press_resource_type>
</post_press_version>
<post_press_version>
<ORDER>2</ORDER>
<post_press_version_op_id>0</post_press_version_op_id>
<version_code>COMM</version_code>
<post_press_resource_type>PB</post_press_resource_type>
</post_press_version>
<post_press_version>
<ORDER>3</ORDER>
<post_press_version_op_id>0</post_press_version_op_id>
<version_code>COMM</version_code>
<post_press_resource_type>PB</post_press_resource_type>
</post_press_version>
</dataroot>
这是我的XSLT;
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- removes the unrelated elements -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="master_version[not(ORDER = //order/ORDERPK)]"/>
<xsl:template match="press_section[not(ORDER = //order/ORDERPK)]"/>
<xsl:template match="version[not(ORDER = //order/ORDERPK)]"/>
<xsl:template match="task_info_press_section[not(ORDER = //order/ORDERPK)]"/>
<xsl:template match="task_info_post_press[not(ORDER = //order/ORDERPK)]"/>
<xsl:template match="post_press_version[not(ORDER = //order/ORDERPK)]"/>
<!-- removes specified nodes from all elements -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ORDER"/>
<xsl:template match="ORDERPK"/>
<xsl:template match="PRESS_x0020_SECTION"/>
<xsl:template match="POST_x0020_PRESS"/>
<!-- Creates attributes against the ORDER element -->
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="order">
<order job_id="{job_id}" site_code="{site_code}" replace="{replace}">
<xsl:apply-templates/>
</order>
</xsl:template>
<xsl:template match="job_id | site_code | replace"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="order">
<order job_id="{@job_id}" site_code="{@site_code}" replace="{Replace}">
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="../master_version"/>
</order>
</xsl:template>
<xsl:template match="Replace"/>
<!-- renames element to specified name -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="task_info_press_section">
<xsl:element name="task_info1">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="task_info_post_press">
<xsl:element name="task_info2">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="dataroot">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(self::master_version)]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这是输出XML;
<?xml version="1.0"?>
<dataroot generated="2015-01-08T09:37:15" xmlns:od="urn:schemas-microsoft-com:officedata">
<order job_id="" site_code="" replace="true">
<job_description>STJ Import - AUG 2007</job_description>
<order_qty>176277</order_qty>
<finishing_style>PB</finishing_style>
<depth>8.25</depth>
<width>10.875</width>
<cover_pagination>4</cover_pagination>
<text_pagination>240</text_pagination>
<delivery_commence_date>2007-11-04</delivery_commence_date>
<delivery_complete_date>2007-11-05</delivery_complete_date>
<job_site>SC</job_site>
<managing_printer>SC</managing_printer>
<is_managing_printer>true</is_managing_printer>
<cust_order_ref>776030</cust_order_ref>
<cust_code>Sears</cust_code>
<cust_contact></cust_contact>
<site_cce_name>Cathy Noble</site_cce_name>
<site_cce_phone>(847) 466 1008</site_cce_phone>
<site_cce_mobile>(847) 477 2008</site_cce_mobile>
<site_cce_email>cathy.noble@superior.com</site_cce_email>
<sales_person_name>Sam Brown</sales_person_name>
<sales_person_phone>(847) 466 1001</sales_person_phone>
<sales_person_mobile>(847) 477 2001</sales_person_mobile>
<sales_person_email>sam.brown@superior.com</sales_person_email>
<master_version>
<version_id></version_id>
<version_code>COMM</version_code>
<version_common>true</version_common>
<version_finished>false</version_finished>
<version_description>Common</version_description>
<version_nett_qty>176262</version_nett_qty>
<version_special_qty>10</version_special_qty>
</master_version>
</order>
<press_section>
<signature_id>001</signature_id>
<sequence_id>1</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>4ppCover</description>
<pagination>4</pagination>
<trim_size>10.875 x 8.375</trim_size>
<folio></folio>
<data_format></data_format>
<data_medium></data_medium>
<data_due></data_due>
</press_section>
<press_section>
<signature_id>001</signature_id>
<sequence_id>2</sequence_id>
<sequence_alpha>A</sequence_alpha>
<description>240ppText</description>
<pagination>240</pagination>
<trim_size>103875 x 8.25</trim_size>
</press_section>
<version>
<version_code>COMM</version_code>
</version>
<task_info1>
<task_sub_job_id>SC10268-001COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>4pp NEWS-NEWS COMM</task_description>
<task_qty_rqd>9636</task_qty_rqd>
<task_resource_id>1</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>18000</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>4</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info1>
<task_info1>
<task_sub_job_id>SC10268-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>19402</task_qty_rqd>
<task_resource_id>1</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>7500</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>1</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info1>
<task_info2>
<task_sub_job_id>SC10268-1COMM</task_sub_job_id>
<task_seq_id>0</task_seq_id>
<task_description>Perfect Binding</task_description>
<task_qty_rqd>19402</task_qty_rqd>
<task_resource_id>10</task_resource_id>
<task_mr_mins>120</task_mr_mins>
<task_run_mins>240</task_run_mins>
<task_run_speed>7500</task_run_speed>
<task_notes>Task Notes</task_notes>
<task_no_up>1</task_no_up>
<task_deadline_date_time></task_deadline_date_time>
<task_pdt>0.0</task_pdt>
</task_info2>
<post_press_version>
<post_press_version_op_id>0</post_press_version_op_id>
<version_code>COMM</version_code>
<post_press_resource_type>PB</post_press_resource_type>
</post_press_version>
</dataroot>
它正在将元素更改为属性,但它不会带来任何数据,将属性留空。
理想情况下,“order”元素应如下所示;
<order job_id="SC10268" site_code="SC" replace="true">
最终,我还希望将其他元素嵌套在Order中,然后在Order中的其他元素中嵌套,但是现在我设法让“master_version”嵌套了,这要归功于本网站上的其他用户大量帮助我!
如果有人知道如何让元素成为属性,而不是丢失它的数据,那么我会很感激帮助。如果需要更多信息,请告诉我。谢谢!
另外作为旁注,是每个节点之前的“tg:”是XML的一部分,还是你认为这只是外国系统导入的一部分?
答案 0 :(得分:2)
首先,您的XSLT代码实在是一团糟,而您没有完全阅读Tim wrote with endless goodwill。例如,仍有多个身份模板。为什么?
job_id
和site_code
不是属性。它们是元素节点。因此,请将匹配order
的模板更改为
<xsl:template match="order">
<order job_id="{job_id}" site_code="{site_code}" replace="{Replace}">
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="../master_version"/>
</order>
</xsl:template>
然后,输出包括
<order job_id="SC10268" site_code="SC" replace="true">