我是 XSL 的新手,我正在编写一个 Unix 脚本,所以我希望你能帮助我。我的问题:我有一个需要解析为 TXT 的 XML,我正在使用 xsltproc 来解析它但是在一个只包含 1 条记录的 XML 中它工作正常,但是有多个记录它会剥离我的第一个 xsl:template。
`<?xml version="1.0"?>
<flxint>
<app>
<comp>269</comp>
<signal>ITMAML</signal>
<sigref>000000003</sigref>
<date>20130606</date>
<time>115316</time>
<id>FTZ</id>
<duns/>
<revision>007</revision>
<data>
<rec>
<rpos>1</rpos>
<change>UPDATE</change>
<itemdef>
<item>MOT-11022H</item>
<cmpn>11022H</cmpn>
<desc>ASSY,CAR KIT,EIHF,T305,SELF IN</desc>
<type>Purchased</type>
<item_group>MOT01P</item_group>
<inv_uom>ea</inv_uom>
<revi>A</revi>
<wh>269021</wh>
<material/>
<standard/>
<prod_type>STD</prod_type>
<item_signal/>
<item_wght>1</item_wght>
<item_wght_unit>kg</item_wght_unit>
<item_text/>
<ipld>
<rpd_plid>TBD</rpd_plid>
<mpnr>0</mpnr>
</ipld>
<ipd>
<order_ltime>0</order_ltime>
</ipd>
<shelf_life>NA</shelf_life>
<shelf_per>0</shelf_per>
<item_height>0</item_height>
<item_width>0</item_width>
<item_depth>0</item_depth>
<item_wght_unit>lb</item_wght_unit>
<item_dim_unit>ft</item_dim_unit>
<abc_code>C</abc_code>
<hml_code/>
<buyer>TBD</buyer>
<inspect>N</inspect>
<coo/>
<rec_early>365</rec_early>
<rec_late>365</rec_late>
<rec_over>0</rec_over>
<rec_under>100</rec_under>
<pur_pricgrp>N/A</pur_pricgrp>
<pur_statgrp>PUR</pur_statgrp>
<pur_statgrp_desc>Purchase Statistic Group</pur_statgrp_desc>
<contact>
<name>TO BE DEFINED</name>
<phone/>
<email/>
</contact>
<iod>
<order_int>5</order_int>
<order_inc>1</order_inc>
<min_qty>1</min_qty>
<plid>TBD</plid>
</iod>
<std_costs>
<std_cost>1</std_cost>
<std_curr>USD</std_curr>
<std_mat>1</std_mat>
<std_op>0</std_op>
<last_calc_date>20130326</last_calc_date>
<last_calc_date_time>120035</last_calc_date_time>
</std_costs>
<sim_pur_pric>
<spp_code>001</spp_code>
<spp_price>1</spp_price>
<spp_unit>ea</spp_unit>
<spp_curr>USD</spp_curr>
<spp_cost_comp>001</spp_cost_comp>
</sim_pur_pric>
<std_costs>
<std_cost>0</std_cost>
<std_curr/>
</std_costs>
<storage_conditions/>
<rohs>N</rohs>
<com_code/>
<ean/>
<eccn/>
<upc/>
<cust_po/>
<cust_po_pos/>
<sel_code/>
<consum_code/>
<rbom_famitem/>
<alt_desc>ASSY,CAR KIT,EIHF,T305,SELF INSTL AR</alt_desc>
<aml/>
<ics>
<code>MOT</code>
<bpid/>
<citem>11022H</citem>
</ics>
<item_data_additions>
<item_data>
<attrno>1</attrno>
<attrname>FTZ Reporting Status</attrname>
<attrval>Y</attrval>
</item_data>
<item_data>
<attrno>2</attrno>
<attrname>HTS Value</attrname>
<attrval>8517620050</attrval>
</item_data>
<item_data>
<attrno>3</attrno>
<attrname>Arctic Fox / Common</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>4</attrno>
<attrname>(4) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>5</attrno>
<attrname>(5) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>6</attrno>
<attrname>(6) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>7</attrno>
<attrname>(7) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>8</attrno>
<attrname>(8) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>9</attrno>
<attrname>(9) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>10</attrno>
<attrname>(10) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>11</attrno>
<attrname>(11) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>12</attrno>
<attrname>(12) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>13</attrno>
<attrname>(13) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>14</attrno>
<attrname>(14) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>15</attrno>
<attrname>(15) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>16</attrno>
<attrname>(16) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>17</attrno>
<attrname>(17) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>18</attrno>
<attrname>(18) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>19</attrno>
<attrname>(19) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>20</attrno>
<attrname>(20) Not Defined</attrname>
<attrval/>
</item_data>
</item_data_additions>
<eng>
<eng_rev>
<revi>A</revi>
<dsca>DAL078075E</dsca>
<orno/>
<eff_date>20130312</eff_date>
<eff_date_time>180825</eff_date_time>
<exp_date/>
<exp_date_time/>
<revi_status>RELEASED</revi_status>
<draw_loc/>
<cad_date/>
<cad_date_time/>
<draw/>
</eng_rev>
</eng>
<aml_add_attrs/>
<sel_code_dsca/>
<rohs_insp>No</rohs_insp>
<log_grpcode/>
</itemdef>
</rec>
<rec>
<rpos>2</rpos>
<change>UPDATE</change>
<itemdef>
<item>MOT-11052N</item>
<cmpn>11052N</cmpn>
<desc>ACCY,ENT/CONCTIV,BT HSET,H560,</desc>
<type>Purchased</type>
<item_group>MOT01P</item_group>
<inv_uom>ea</inv_uom>
<revi>A</revi>
<wh>269021</wh>
<material/>
<standard/>
<prod_type>STD</prod_type>
<item_signal/>
<item_wght>1</item_wght>
<item_wght_unit>kg</item_wght_unit>
<item_text/>
<ipld>
<rpd_plid>TBD</rpd_plid>
<mpnr>0</mpnr>
</ipld>
<ipd>
<order_ltime>0</order_ltime>
</ipd>
<shelf_life>NA</shelf_life>
<shelf_per>0</shelf_per>
<item_height>0</item_height>
<item_width>0</item_width>
<item_depth>0</item_depth>
<item_wght_unit>lb</item_wght_unit>
<item_dim_unit>ft</item_dim_unit>
<abc_code>C</abc_code>
<hml_code/>
<buyer>TBD</buyer>
<inspect>N</inspect>
<coo/>
<rec_early>365</rec_early>
<rec_late>365</rec_late>
<rec_over>0</rec_over>
<rec_under>100</rec_under>
<pur_pricgrp>N/A</pur_pricgrp>
<pur_statgrp>PUR</pur_statgrp>
<pur_statgrp_desc>Purchase Statistic Group</pur_statgrp_desc>
<contact>
<name>TO BE DEFINED</name>
<phone/>
<email/>
</contact>
<iod>
<order_int>5</order_int>
<order_inc>1</order_inc>
<min_qty>1</min_qty>
<plid>TBD</plid>
</iod>
<std_costs>
<std_cost>1</std_cost>
<std_curr>USD</std_curr>
<std_mat>1</std_mat>
<std_op>0</std_op>
<last_calc_date>20130326</last_calc_date>
<last_calc_date_time>120035</last_calc_date_time>
</std_costs>
<sim_pur_pric>
<spp_code>001</spp_code>
<spp_price>1</spp_price>
<spp_unit>ea</spp_unit>
<spp_curr>USD</spp_curr>
<spp_cost_comp>001</spp_cost_comp>
</sim_pur_pric>
<std_costs>
<std_cost>0</std_cost>
<std_curr/>
</std_costs>
<storage_conditions/>
<rohs>N</rohs>
<com_code/>
<ean/>
<eccn/>
<upc/>
<cust_po/>
<cust_po_pos/>
<sel_code/>
<consum_code/>
<rbom_famitem/>
<alt_desc>ACCY,ENT/CONCTIV,BT HSET,H560,SLVR ARG</alt_desc>
<aml/>
<ics>
<code>MOT</code>
<bpid/>
<citem>11052N</citem>
</ics>
<item_data_additions>
<item_data>
<attrno>1</attrno>
<attrname>FTZ Reporting Status</attrname>
<attrval>Y</attrval>
</item_data>
<item_data>
<attrno>2</attrno>
<attrname>HTS Value</attrname>
<attrval>8517620050</attrval>
</item_data>
<item_data>
<attrno>3</attrno>
<attrname>Arctic Fox / Common</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>4</attrno>
<attrname>(4) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>5</attrno>
<attrname>(5) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>6</attrno>
<attrname>(6) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>7</attrno>
<attrname>(7) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>8</attrno>
<attrname>(8) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>9</attrno>
<attrname>(9) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>10</attrno>
<attrname>(10) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>11</attrno>
<attrname>(11) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>12</attrno>
<attrname>(12) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>13</attrno>
<attrname>(13) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>14</attrno>
<attrname>(14) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>15</attrno>
<attrname>(15) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>16</attrno>
<attrname>(16) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>17</attrno>
<attrname>(17) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>18</attrno>
<attrname>(18) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>19</attrno>
<attrname>(19) Not Defined</attrname>
<attrval/>
</item_data>
<item_data>
<attrno>20</attrno>
<attrname>(20) Not Defined</attrname>
<attrval/>
</item_data>
</item_data_additions>
<eng>
<eng_rev>
<revi>A</revi>
<dsca>DAL078075E</dsca>
<orno/>
<eff_date>20130312</eff_date>
<eff_date_time>180826</eff_date_time>
<exp_date/>
<exp_date_time/>
<revi_status>RELEASED</revi_status>
<draw_loc/>
<cad_date/>
<cad_date_time/>
<draw/>
</eng_rev>
</eng>
<aml_add_attrs/>
<sel_code_dsca/>
<rohs_insp>No</rohs_insp>
<log_grpcode/>
</itemdef>
</rec>
</data>
</app>
</flxint>`
到目前为止,这是我的 XSL:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="flxint">
<xsl:apply-templates select="app"/>
</xsl:template>
<xsl:template match="app">
<xsl:text>10563|</xsl:text>
<xsl:value-of select='date'/><xsl:text>T</xsl:text>
<xsl:value-of select='time'/><xsl:text>|</xsl:text>
<xsl:apply-templates select="data"/>
</xsl:template>
<xsl:template match="data">
<xsl:apply-templates select="rec"/>
</xsl:template>
<xsl:template match="rec">
<xsl:apply-templates select="itemdef"/>
</xsl:template>
<xsl:template match="itemdef">
<xsl:apply-templates select="ics"/>
<xsl:text>|</xsl:text>
<xsl:text>IM|</xsl:text>
<xsl:value-of select='desc'/><xsl:text>|</xsl:text>
<xsl:value-of select='inv_uom'/><xsl:text>|</xsl:text>
<xsl:value-of select='item_wght'/><xsl:text>|</xsl:text>
<xsl:value-of select='item_wght_unit'/><xsl:text>|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>USD|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>E|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>HTSNumber|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:value-of select='coo'/><xsl:text>|</xsl:text>
<xsl:apply-templates select="aml"/>
<xsl:apply-templates select="sim_pur_pric"/>
</xsl:template>
<xsl:template match="ics">
<xsl:value-of select='citem'/><xsl:text>|</xsl:text>
</xsl:template>
<xsl:template match="aml">
<xsl:apply-templates select="aml_rec"/>
</xsl:template>
<xsl:template match="aml_rec">
<xsl:value-of select='add_item_info'/><xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
</xsl:template>
<xsl:template match="sim_pur_pric">
<xsl:value-of select='spp_price'/><xsl:text>|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>USD|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>0|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|
</xsl:text>
</xsl:template>
</xsl:stylesheet>
这是输出,第一行可以,但第二行不行,所以
10563|20130606T115316|11022H||IM|ASSY,CAR KIT,EIHF,T305,SELF IN|ea|1|kg|0|USD||||E|||||HTSNumber|||1|0|USD|0|0|||||||0||0|||||
11052N||IM|ACCY,ENT/CONCTIV,BT HSET,H560,|ea|1|kg|0|USD||||E|||||HTSNumber|||1|0|USD|0|0|||||||0||0|||||
11054N||IM|ACCY,MOB/VOICE,BT HSET,H15,LA|ea|1|kg|0|USD||||E|||||HTSNumber|||1|0|USD|0|0|||||||0||0|||||
11061N||IM|ACCY,MUSIC/ENT,SPKR,EQ5,COLDPL|ea|1|kg|0|USD||||E|||||HTSNumber|||||||1|0|USD|0|0|||||||0||0|||||