没有输出的XSLT转换

时间:2017-02-07 21:55:40

标签: xml xslt transform

我有以下XML文件,并希望创建一个XSLT转换为带有标题的表,例如。

Item No.  Part Number    Description                Material     etc.
1         0040-84339     Rotor, Wafer Head MK1   
2         0020-93948     Insulator, Echuck Contact

这是XML。我已经尝试了一些XSLT创建工具,但是在创建所需输出方面运气很少。有人可以定义基本的XSLT结构,以根据需要格式化此XML。

<?xml version="1.0" encoding="UTF-8"?>
<xml>
    <transactions>
        <transaction date="1485976336" type="export_bom_spreadsheet" vaultname="PDM_Pro">
            <bom document_id="2113" document_path="\EPDM Demo Files\9011-01765.SLDDRW" id="2133"
                name="9011-01765.SLDDRW: Bill of Materials1" path="\EPDM Demo Files\" type="3">
                <bomheader>
                    <bomcol alignment="center" col_no="0" name="ITEM NO."/>
                    <bomcol alignment="center" col_no="1" name="PART NUMBER"/>
                    <bomcol alignment="center" col_no="2" name="DESCRIPTION"/>
                    <bomcol alignment="center" col_no="3" name="MATERIAL"/>
                    <bomcol alignment="center" col_no="4" name="STOCK SIZE"/>
                    <bomcol alignment="center" col_no="5" name="WEIGHT"/>
                    <bomcol alignment="center" col_no="6" name="VENDOR"/>
                    <bomcol alignment="center" col_no="7" name="Default/QTY."/>
                </bomheader>
                <bomrow document_id="2120" path="\EPDM Demo Files\0040-84339.sldasm" row_no="0">
                    <bomcell col_no="0" value="1"/>
                    <bomcell col_no="1" value="0040-84339"/>
                    <bomcell col_no="2" value="ROTOR, WAFER HEAD MK1"/>
                    <bomcell col_no="3" value=""/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value=""/>
                    <bomcell col_no="7" value="1"/>
                </bomrow>
                <bomrow document_id="2126" path="\EPDM Demo Files\0020-53948.sldprt" row_no="1">
                    <bomcell col_no="0" value="2"/>
                    <bomcell col_no="1" value="0020-53948"/>
                    <bomcell col_no="2" value="INSULATOR, ECHUCK CONTACT"/>
                    <bomcell col_no="3" value="PEEK"/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value=""/>
                    <bomcell col_no="7" value="2"/>
                </bomrow>
                <bomrow document_id="2125" path="\EPDM Demo Files\0020-53949.sldprt" row_no="2">
                    <bomcell col_no="0" value="3"/>
                    <bomcell col_no="1" value="0020-53949"/>
                    <bomcell col_no="2" value="HIGH VOLTAGE CONTACT"/>
                    <bomcell col_no="3" value=""/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value=""/>
                    <bomcell col_no="7" value="2"/>
                </bomrow>
                <bomrow document_id="2115" path="\EPDM Demo Files\9010-01765-1.sldprt" row_no="3">
                    <bomcell col_no="0" value="4"/>
                    <bomcell col_no="1" value="3700-04467"/>
                    <bomcell col_no="2" value="O-RING,  BUNA-N 2-011 70 DURO"/>
                    <bomcell col_no="3" value="-"/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value="PARKER SEALS"/>
                    <bomcell col_no="7" value="2"/>
                </bomrow>
                <bomrow document_id="2119" path="\EPDM Demo Files\3690-05375.sldprt" row_no="4">
                    <bomcell col_no="0" value="5"/>
                    <bomcell col_no="1" value="3690-05375"/>
                    <bomcell col_no="2" value="SET SCR CUP PT STEEL,  M2.5 X 5"/>
                    <bomcell col_no="3" value="STEEL"/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value="STOCK DRIVE"/>
                    <bomcell col_no="7" value="2"/>
                </bomrow>
                <bomrow document_id="2117" path="\EPDM Demo Files\3700-02453.sldprt" row_no="5">
                    <bomcell col_no="0" value="6"/>
                    <bomcell col_no="1" value="801655-150"/>
                    <bomcell col_no="2" value="O-RING, BUNA N 2-150 N674-70"/>
                    <bomcell col_no="3" value=""/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value=""/>
                    <bomcell col_no="7" value="1"/>
                </bomrow>
                <bomrow document_id="2118" path="\EPDM Demo Files\3700-01044.sldprt" row_no="6">
                    <bomcell col_no="0" value="7"/>
                    <bomcell col_no="1" value="3700-01044"/>
                    <bomcell col_no="2" value="O-RING 2-224 BUNA-N"/>
                    <bomcell col_no="3" value="-"/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value="Parker Seals"/>
                    <bomcell col_no="7" value="2"/>
                </bomrow>
                <bomrow document_id="2116" path="\EPDM Demo Files\3700-98003.sldprt" row_no="7">
                    <bomcell col_no="0" value="8"/>
                    <bomcell col_no="1" value="3700-98003"/>
                    <bomcell col_no="2" value="O-RING, 2-011 BUNA-N"/>
                    <bomcell col_no="3" value="RUBBER"/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value="Parker Seals"/>
                    <bomcell col_no="7" value="1"/>
                </bomrow>
                <bomrow document_id="2127"
                    path="\EPDM Demo Files\Additional File Folder\0020-53947.sldprt" row_no="8">
                    <bomcell col_no="0" value="9"/>
                    <bomcell col_no="1" value="0020-53947"/>
                    <bomcell col_no="2" value=""/>
                    <bomcell col_no="3" value=""/>
                    <bomcell col_no="4" value=""/>
                    <bomcell col_no="5" value=""/>
                    <bomcell col_no="6" value=""/>
                    <bomcell col_no="7" value="1"/>
                </bomrow>
            </bom>
        </transaction>
    </transactions>
</xml>

1 个答案:

答案 0 :(得分:1)

您可以从此开始,然后根据需要进行优化:

<xsl:template match="bom">
  <table>
   <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="bomheader">
  <thead>
   <xsl:apply-templates/>
  </thead>
</xsl:template>

<xsl:template match="bomheader/bomcol">
  <th>
   <xsl:value-of select="@value"/>
  </th>
</xsl:template>

<xsl:template match="bomrow">
  <tr>
   <xsl:apply-templates/>
  </tr>
</xsl:template>

<xsl:template match="bomcell">
  <td>
   <xsl:value-of select="@value"/>
  </td>
</xsl:template>