2013-01-07 59 views
1

我遇到了正确格式化数据的问题。顶级节点是Part。该节点下面的元素是AML和文档。反洗钱和文件可以是不同的值。 AML可以大于文档和文档可以大于AML。我需要Documents和AML的元素位于同一行,以便表格格式正确。请让我知道如果你需要更多的信息,并感谢你的帮助,我们非常感谢。XSLT动态行

数据

<Item type="Part"> 
    <item_number>E008643</item_number> 
    <Relationships> 
     <Item type="Part AML"> 
     <related_id keyed_name="0000-009" type="Manufacturer Part"> 
      <Item type="Manufacturer Part"> 
      <manufacturer keyed_name="Fasteners Co." type="Manufacturer"></manufacturer> 
      <item_number>0000-009</item_number> 
      </Item> 
     </related_id> 
     <state>Preliminary</state> 
     </Item> 
     <Item type="Part AML"> 
     <related_id keyed_name="1234" type="Manufacturer Part"> 
      <Item type="Manufacturer Part"> 
      <id keyed_name="1234" type="Manufacturer Part"></id> 
      <manufacturer keyed_name="Vishay/Dale" type="Manufacturer"></manufacturer> 
      <item_number>1234</item_number> 
      </Item> 
     </related_id> 
     <state>Preliminary</state> 
     </Item> 
     <Item type="Part Document"> 
     <related_id keyed_name="D000006" type="Document"> 
      <Item type="Document"> 
      <id keyed_name="D000006" type="Document"></id> 
      <major_rev>B</major_rev> 
      <name>Hardware Doc</name> 
      <item_number>D000006</item_number> 
      </Item> 
     </related_id> 
     </Item> 
     <Item type="Part Document"> 
     <related_id keyed_name="D000005" type="Document"> 
      <Item type="Document"> 
      <major_rev>B</major_rev> 
      <name>Firmware</name> 
      <item_number>D000005</item_number> 
      </Item> 
     </related_id> 
     </Item> 
     <Item type="Part Document"> 
     <related_id keyed_name="D000003" type="Document"> 
      <Item type="Document"> 
      <major_rev>A</major_rev> 
      <name>Design Spec</name> 
      <item_number>D000003</item_number> 
      </Item> 
     </related_id> 
     </Item> 
     <Item type="Part BOM"> 
     <related_id keyed_name="E000371" type="Part"> 
      <Item type="Part"> 
      <item_number>E000371</item_number> 
      <Relationships> 
       <Item type="Part AML"> 
       <related_id keyed_name="3Z1JTTD" type="Manufacturer Part"> 
        <Item type="Manufacturer Part"> 
        <manufacturer keyed_name="Speer" type="Manufacturer"></manufacturer> 
        <item_number>3Z1JTTD</item_number> 
        </Item> 
       </related_id> 
       <state>Preliminary</state> 
       </Item> 
       <Item type="Part AML"> 
       <related_id keyed_name="000T" type="Manufacturer Part"> 
        <Item type="Manufacturer Part"> 
        <manufacturer keyed_name="Nickel" type="Manufacturer"></manufacturer> 
        <item_number>000T</item_number> 
        </Item> 
       </related_id> 
       <source_id keyed_name="E000371" type="Part"></source_id> 
       <state>Preliminary</state> 
       </Item> 
       <Item type="Part AML"> 
       <related_id keyed_name="R00V" type="Manufacturer Part"> 
        <Item type="Manufacturer Part"> 
        <manufacturer keyed_name="Sonic" type="Manufacturer"></manufacturer> 
        <item_number>R00V</item_number> 
        </Item> 
       </related_id> 
       <state>Preliminary</state> 
       </Item> 
       <Item type="Part AML"> 
       <related_id keyed_name="TRF" type="Manufacturer Part"> 
        <Item type="Manufacturer Part"> 
        <manufacturer keyed_name="Components" type="Manufacturer"></manufacturer> 
        <item_number>TRF</item_number> 
        </Item> 
       </related_id> 
       <state>Preliminary</state> 
       </Item> 
       <Item type="Part AML"> 
       <related_id keyed_name="70RL" type="Manufacturer Part"> 
        <Item type="Manufacturer Part"> 
        <manufacturer keyed_name="Comp" type="Manufacturer"></manufacturer> 
        <item_number>70RL</item_number> 
        </Item> 
       </related_id> 
       <state>Preliminary</state> 
       </Item> 
       <Item type="Part Document"> 
       <related_id keyed_name="D000007" type="Document"> 
        <Item type="Document"> 
        <major_rev>B</major_rev> 
        <name>BOX</name> 
        <item_number>D000007</item_number> 
        </Item> 
       </related_id> 
       <state is_null="1" /> 
       </Item> 
       <Item type="Part Document"> 
       <related_id keyed_name="D000008" type="Document"> 
        <Item type="Document"> 
        <major_rev>A</major_rev> 
        <name>SOCKET</name> 
        <item_number>D000008</item_number> 
        </Item> 
       </related_id> 
       <state is_null="1" /> 
       </Item> 
      </Relationships> 
      </Item> 
     </related_id> 
     </Item> 
</Relationships>   

样式表

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:aras="http://www.aras-corp.com" exclude-result-prefixes="msxsl"> 
    <xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"></xsl:output> 

    <xsl:template match="/"> 
     <html> 
      <head></head> 
      <style type="text/css" userData="Global"> 
     table {empty-cells:show; border-collapse:collapse;} 
     th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;} 
     td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;} 
     td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;} 
     </style> 
      <body topmargin="50" leftmargin="50"> 
      <table border="0" cellspacing="0" cellpadding="0" width="1850"> 
       <tr valign="top"> 
       <td class="noBorder" align="left" colspan="9" uniqueID="ms__id39"> 
      </td> 
     </tr> 
       <tr valign="bottom"> 
       <td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22">Bill of Materials Report -    <xsl:value-of select="//Item/name"></xsl:value-of> Rev    <xsl:value-of select="//Item/major_rev"></xsl:value-of> 
       </td> 
       <td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23">Generated on:    <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length &lt; n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script> 
       </td> 
     </tr> 
       <tr> 
       <th>Part Number</th> 
       <th>Manufacturer</th> 
       <th>Manufacturer Part</th> 
       <th>Document Number</th> 
       <th>Document Name</th> 
       <th>Document Rev</th> 
      </tr> 
     <xsl:apply-templates select="//Item[@type='Part']"></xsl:apply-templates> 
     </table> 
     </body> 
      <script src="../../javascript/PopupMenu.js"></script> 
      <script src="../../javascript/PopupMenu.js"></script> 
      <script src="../../javascript/PopupMenu.js"></script> 
      <script src="../../javascript/PopupMenu.js"></script> 
     </html> 
    </xsl:template> 
     <xsl:template match="Item[@type='Part']"> 

     <!-- Find the number Row Span --> 
     <xsl:variable name="AML"> 
      <xsl:choose> 
      <xsl:when test="count(Relationships/Item[@type='Part AML'])=0">1</xsl:when>   
      <xsl:otherwise> 
       <xsl:value-of select="count(Relationships/Item[@type='Part AML'])"></xsl:value-of> 
      </xsl:otherwise> 
     </xsl:choose> 
     </xsl:variable> 
     <xsl:variable name="Doc"> 
      <xsl:choose> 
      <xsl:when test="count(Relationships/Item[@type='Part Document'])=0">1</xsl:when>   
      <xsl:otherwise> 
       <xsl:value-of select="count(Relationships/Item[@type='Part Document'])"></xsl:value-of> 
      </xsl:otherwise> 
     </xsl:choose> 
     </xsl:variable> 
     <xsl:variable name="rowCount"> 
     <xsl:choose> 
      <xsl:when test="$AML &lt; $Doc"><xsl:value-of select="$Doc"></xsl:value-of></xsl:when> 
      <xsl:otherwise> 
      <xsl:value-of select="$AML"></xsl:value-of>  
      </xsl:otherwise> 
     </xsl:choose> 
     </xsl:variable> 

    <!-- Grab values --> 
     <tr> 
      <td rowspan="{$rowCount}" width="5%" align="center" uniqueID="ms__id16"> 
      <xsl:value-of select="item_number"></xsl:value-of> 
      </td>  
      <td width="13%" align="center" uniqueID="ms__id26"> 
      <xsl:value-of select="Relationships/Item[@type='Part AML'][1]/related_id/Item/manufacturer/@keyed_name"></xsl:value-of> 
      </td> 
      <td width="13%" align="center" uniqueID="ms__id27"> 
      <xsl:value-of select="Relationships/Item[@type='Part AML'][1]/related_id/Item/item_number"></xsl:value-of> 
      </td> 
      <td width="5%" align="center" uniqueID="ms__id28"> 
      <xsl:value-of select="Relationships/Item[@type='Part Document'][1]/related_id/Item/item_number"></xsl:value-of> 
      </td> 
      <td width="13%px" align="center" uniqueID="ms__id29"> 
      <xsl:value-of select="Relationships/Item[@type='Part Document'][1]/related_id/Item/name"></xsl:value-of> 
      </td> 
      <td width="8%" align="center" uniqueID="ms__id30"> 
      <xsl:value-of select="Relationships/Item[@type='Part Document'][1]/related_id/Item/major_rev"></xsl:value-of> 
      </td> 
      <td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id37"> 
      <xsl:value-of select="count(Relationships/Item[@type='Part AML'])"></xsl:value-of> 
      </td> 
      <td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id38"> 
      <xsl:value-of select="count(Relationships/Item[@type='Part Document'])"></xsl:value-of> 
      </td> 
      <td rowspan="{$rowCount}" width="8%" align="center" uniqueID="ms__id40"> 
      <xsl:value-of select="position() mod 2 = 1"></xsl:value-of> 
      </td> 
     </tr> 

    <!-- Assing first row for AML and Doc --> 
     <xsl:apply-templates select="Relationships/Item[@type='Part AML'][position()!=1]|Relationships/Item[@type='Part Document'][position()!=1]"></xsl:apply-templates> 
    </xsl:template> 

    <!-- AML and Doc Rows 2+ -->  
     <xsl:template match="text()" /> 

     <xsl:template match="Item[@type = 'Part AML'][not(following-sibling::Item[1]/@type = 'Part Document')]"> 
     <xsl:call-template name="ItemRow"> 
      <xsl:with-param name="AmlItem" select="." /> 
     </xsl:call-template> 
     </xsl:template> 

     <xsl:template match="Item[@type='Part Document']"> 
     <xsl:variable name="lastItem" select="preceding-sibling::Item[1][@type = 'Part AML']" /> 

     <xsl:call-template name="ItemRow"> 
      <xsl:with-param name="AmlItem" select="$lastItem" /> 
      <xsl:with-param name="PartDocument" select="." /> 
     </xsl:call-template> 
     </xsl:template> 

     <xsl:template name="ItemRow"> 
     <xsl:param name="AmlItem" /> 
     <xsl:param name="PartDocument" select="_" /> 

     <xsl:variable name="rowData"> 
      <row value="{$AmlItem/related_id/Item/manufacturer/@keyed_name}" id="32" /> 
      <row value="{$AmlItem/related_id/Item[@type='Manufacturer Part']/item_number}" id="33" /> 
      <row value="{$PartDocument/related_id[@type='Document']/Item/item_number}" id="34" /> 
      <row value="{$PartDocument/related_id[@type='Document']/Item/name}" id="35" /> 
      <row value="{$PartDocument/related_id[@type='Document']/Item/major_rev}" id="36" /> 
     </xsl:variable> 

     <tr> 
      <xsl:for-each select="msxsl:node-set($rowData)/row"> 
      <td width="13%" align="center" uniqueID="ms__id{@id}"> 
       <xsl:value-of select="@value"/> 
      </td> 
      </xsl:for-each> 
     </tr> 
     </xsl:template> 
    </xsl:stylesheet> 

输出12年1月7日

 <td width="13%" align="center" uniqueID="ms__id32">Bobs Workshop</td> 
    <td width="13%" align="center" uniqueID="ms__id33">1234</td> 
    <td width="13%" align="center" uniqueID="ms__id34">D000005</td> 
    <td width="13%" align="center" uniqueID="ms__id35">Firmware</td> 
    <td width="13%" align="center" uniqueID="ms__id36">B</td> 
    <td width="13%" align="center" uniqueID="ms__id34">D000003</td> 
    <td width="13%" align="center" uniqueID="ms__id35">Design Spec</td> 
    <td width="13%" align="center" uniqueID="ms__id36">A</td> 

所需的输出

<!-- If both present --> 
    <tr> 
    <td width="13%" align="center" uniqueID="ms__id32">Bobs Workshop</td> 
    <td width="13%" align="center" uniqueID="ms__id33">1234</td> 
    <td width="13%" align="center" uniqueID="ms__id34">D000005</td> 
    <td width="13%" align="center" uniqueID="ms__id35">Firmware</td> 
    <td width="13%" align="center" uniqueID="ms__id36">B</td> 
    </tr>   
<!-- If only Doc is present --> 
    <tr> 
    <td width="13%" align="center" uniqueID="ms__id32">""</td> 
    <td width="13%" align="center" uniqueID="ms__id33">""</td> 
    <td width="13%" align="center" uniqueID="ms__id34">D000003</td> 
    <td width="13%" align="center" uniqueID="ms__id35">Design Spec</td> 
    <td width="13%" align="center" uniqueID="ms__id36">A</td> 
    </tr> 
<!-- If only AML is present --> 
    <tr> 
    <td width="13%" align="center" uniqueID="ms__id32">Nickel</td> 
    <td width="13%" align="center" uniqueID="ms__id33">000T</td> 
    <td width="13%" align="center" uniqueID="ms__id34">""</td> 
    <td width="13%" align="center" uniqueID="ms__id35">""</td> 
    <td width="13%" align="center" uniqueID="ms__id36">""</td> 
    </tr> 

希望的满HTML输出

<html xmlns:aras="http://www.aras-corp.com"> 
     <head> 
     <META http-equiv="Content-Type" content="text/html; charset=utf-16"> 
     </head> 
     <style type="text/css" userData="Global"> 
     table {empty-cells:show; border-collapse:collapse;} 
     th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;} 
     td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;} 
     td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;} 
     </style> 
     <body topmargin="50" leftmargin="50"> 
     <table border="0" cellspacing="0" cellpadding="0" width="1850"> 
      <tr valign="top"> 
      </tr> 
      <tr valign="bottom"> 
      <td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22">Bill of Materials Report -    9.6 Hz Parts Rev    1</td> 
      <td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23">Generated on:    <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length < n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script></td> 
      </tr> 
      <tr> 
      <th colspan="6">Indenture Level</th> 
      <th>Part Number</th> 
      <th>Legacy Part Number</th> 
      <th>Revision</th> 
      <th>Name</th> 
      <th>Description</th> 
      <th>Parameters</th> 
      <th>RoHS/Pb-Free</th> 
      <th>Quantity</th> 
      <th>Reference Designator</th> 
      <th>Manufacturer</th> 
      <th>Manufacturer Part</th> 
      <th>Document Number</th> 
      <th>Document Name</th> 
      <th>Document Rev</th> 
      <th>Pos AML</th> 
      <th>Pos Doc</th> 
      <th>Mod</th> 
      </tr> 
      <tr> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id10">0</td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id11"></td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id12"></td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id13"></td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id14"></td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id15"></td> 
      <td rowspan="3" width="5%" align="center" uniqueID="ms__id16">E008643</td> 
      <td rowspan="3" width="5%" align="center" uniqueID="ms__id17"></td> 
      <td rowspan="3" width="2%" align="center" uniqueID="ms__id18">1</td> 
      <td rowspan="3" width="13%" align="center" uniqueID="ms__id19">9.6 Hz Parts</td> 
      <td rowspan="3" width="13%" align="center" uniqueID="ms__id20">Test</td> 
      <td rowspan="3" width="13%" align="center" uniqueID="ms__id21">Assembly</td> 
      <td rowspan="3" width="5%" align="center" uniqueID="ms__id22"></td> 
      <td rowspan="3" width="5%" align="center" uniqueID="ms__id23">1</td> 
      <td rowspan="3" width="5%" align="center" uniqueID="ms__id24"></td> 
      <td width="13%" align="center" uniqueID="ms__id26">Fasteners Co.</td> 
      <td width="13%" align="center" uniqueID="ms__id27">009</td> 
      <td width="5%" align="center" uniqueID="ms__id28">D000006</td> 
      <td width="13%px" align="center" uniqueID="ms__id29">Hardware Doc</td> 
      <td width="8%" align="center" uniqueID="ms__id30">B</td> 
      <td rowspan="3" width="8%" align="center" uniqueID="ms__id37">2</td> 
      <td rowspan="3" width="8%" align="center" uniqueID="ms__id38">3</td> 
      <td rowspan="3" width="8%" align="center" uniqueID="ms__id40">true</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32">Vishay/Dale</td> 
      <td width="13%" align="center" uniqueID="ms__id33">1234</td> 
      <td width="13%" align="center" uniqueID="ms__id34">D000005</td> 
      <td width="13%" align="center" uniqueID="ms__id35">Firmware</td> 
      <td width="13%" align="center" uniqueID="ms__id36">B</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32"></td> 
      <td width="13%" align="center" uniqueID="ms__id33"></td> 
      <td width="13%" align="center" uniqueID="ms__id34">D000003</td> 
      <td width="13%" align="center" uniqueID="ms__id35">Design Spec</td> 
      <td width="13%" align="center" uniqueID="ms__id36">A</td> 
      </tr> 
      <tr> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id10"></td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id11">1</td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id12"></td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id13"></td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id14"></td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id15"></td> 
      <td rowspan="5" width="5%" align="center" uniqueID="ms__id16">E000371</td> 
      <td rowspan="5" width="5%" align="center" uniqueID="ms__id17">0061</td> 
      <td rowspan="5" width="2%" align="center" uniqueID="ms__id18">A</td> 
      <td rowspan="5" width="13%" align="center" uniqueID="ms__id19">0?</td> 
      <td rowspan="5" width="13%" align="center" uniqueID="ms__id20">Thick Film ''</td> 
      <td rowspan="5" width="13%" align="center" uniqueID="ms__id21">0, 100, 0.05</td> 
      <td rowspan="5" width="5%" align="center" uniqueID="ms__id22">Yes</td> 
      <td rowspan="5" width="5%" align="center" uniqueID="ms__id23">1</td> 
      <td rowspan="5" width="5%" align="center" uniqueID="ms__id24">R34</td> 
      <td width="13%" align="center" uniqueID="ms__id26">Speer</td> 
      <td width="13%" align="center" uniqueID="ms__id27">RK73Z1JTTD</td> 
      <td width="5%" align="center" uniqueID="ms__id28">D000010</td> 
      <td width="13%px" align="center" uniqueID="ms__id29">BOX</td> 
      <td width="8%" align="center" uniqueID="ms__id30">B</td> 
      <td rowspan="5" width="8%" align="center" uniqueID="ms__id37">5</td> 
      <td rowspan="5" width="8%" align="center" uniqueID="ms__id38">3</td> 
      <td rowspan="5" width="8%" align="center" uniqueID="ms__id40">false</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32">Nickel</td> 
      <td width="13%" align="center" uniqueID="ms__id33">000T</td> 
      <td width="13%" align="center" uniqueID="ms__id34">D000011</td> 
      <td width="13%" align="center" uniqueID="ms__id35">SOCKET</td> 
      <td width="13%" align="center" uniqueID="ms__id36">A</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32">Sonic</td> 
      <td width="13%" align="center" uniqueID="ms__id33">R00V</td> 
      <td width="13%" align="center" uniqueID="ms__id34">D000007</td> 
      <td width="13%" align="center" uniqueID="ms__id35">MOUNT</td> 
      <td width="13%" align="center" uniqueID="ms__id36">A</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32">NIC</td> 
      <td width="13%" align="center" uniqueID="ms__id33">OTRF</td> 
      <td width="13%" align="center" uniqueID="ms__id34"></td> 
      <td width="13%" align="center" uniqueID="ms__id35"></td> 
      <td width="13%" align="center" uniqueID="ms__id36"></td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32">Test</td> 
      <td width="13%" align="center" uniqueID="ms__id33">9874</td> 
      <td width="13%" align="center" uniqueID="ms__id34"></td> 
      <td width="13%" align="center" uniqueID="ms__id35"></td> 
      <td width="13%" align="center" uniqueID="ms__id36"></td> 
      </tr> 
      <tr> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id10"></td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id11">1</td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id12"></td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id13"></td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id14"></td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id15"></td> 
      <td rowspan="2" width="5%" align="center" uniqueID="ms__id16">E001163</td> 
      <td rowspan="2" width="5%" align="center" uniqueID="ms__id17">0145</td> 
      <td rowspan="2" width="2%" align="center" uniqueID="ms__id18">A</td> 
      <td rowspan="2" width="13%" align="center" uniqueID="ms__id19">8200</td> 
      <td rowspan="2" width="13%" align="center" uniqueID="ms__id20">PPS Film ''</td> 
      <td rowspan="2" width="13%" align="center" uniqueID="ms__id21"> 
      </td> 
      <td rowspan="2" width="5%" align="center" uniqueID="ms__id22">Yes</td> 
      <td rowspan="2" width="5%" align="center" uniqueID="ms__id23">30</td> 
      <td rowspan="2" width="5%" align="center" uniqueID="ms__id24">C1-C5,C12,C17,C22,C25,C27-C29,C31</td> 
      <td width="13%" align="center" uniqueID="ms__id26">Sonic</td> 
      <td width="13%" align="center" uniqueID="ms__id27">822GX5</td> 
      <td width="5%" align="center" uniqueID="ms__id28">D000012</td> 
      <td width="13%px" align="center" uniqueID="ms__id29">Doc Test</td> 
      <td width="8%" align="center" uniqueID="ms__id30">A</td> 
      <td rowspan="2" width="8%" align="center" uniqueID="ms__id37">2</td> 
      <td rowspan="2" width="8%" align="center" uniqueID="ms__id38">2</td> 
      <td rowspan="2" width="8%" align="center" uniqueID="ms__id40">true</td> 
      </tr> 
      <tr> 
      <td width="13%" align="center" uniqueID="ms__id32"></td> 
      <td width="13%" align="center" uniqueID="ms__id33"></td> 
      <td width="13%" align="center" uniqueID="ms__id34">D000008</td> 
      <td width="13%" align="center" uniqueID="ms__id35">ADAPTER</td> 
      <td width="13%" align="center" uniqueID="ms__id36">A</td> 
      </tr> 
     </table> 
     </body><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script><script src="../../javascript/PopupMenu.js"></script></html> 

回答

2

您使用的是哪种XSLT处理器?

我相信这应该做你想要什么:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:aras="http://www.aras-corp.com" exclude-result-prefixes="msxsl"> 
    <xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"></xsl:output> 

    <xsl:template match="/"> 
    <html> 
     <head></head> 
     <style type="text/css" userData="Global"> 
     table {empty-cells:show; border-collapse:collapse;} 
     th {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid; background-color:#CCCCCC; text-transform:capitalize;} 
     td {font-family:helvetica; font-size:8pt; padding:2px; border:1px #000000 solid;} 
     td.noBorder {font-family:helvetica; font-size:8pt; padding:2px; border-width:0;} 
     </style> 
     <body topmargin="50" leftmargin="50"> 
     <table border="0" cellspacing="0" cellpadding="0" width="1850"> 
      <tr valign="top"> 
      <td class="noBorder" align="left" colspan="9" uniqueID="ms__id39"> 
      </td> 
      </tr> 
      <tr valign="bottom"> 
      <td class="noBorder" colspan="13" style="font-family:helvetica;font-size:15pt;color:#DA1943;padding:2px;" align="left" uniqueID="ms__id22"> 
       Bill of Materials Report -    <xsl:value-of select="//Item/name"></xsl:value-of> Rev    <xsl:value-of select="//Item/major_rev"></xsl:value-of> 
      </td> 
      <td class="noBorder" colspan="7" style="font-family:helvetica;font-size:10pt;padding:2px;" align="right" uniqueID="ms__id23"> 
       Generated on:    <script>function m00(r, n){r += ""; if (!n) n = 2; while(r.length &lt; n){r = "0" + r;} return r;} var dt = new Date(); var a = top.opener.top.aras; if (a){var s = m00(dt.getUTCFullYear(),4)+"-"+m00((dt.getUTCMonth()+1))+"-"+m00(dt.getUTCDate())+"T"+m00(dt.getUTCHours())+":"+m00(dt.getUTCMinutes())+":"+m00(dt.getUTCSeconds())+"+0000"; s = a.convertToNeutral(s, "date", "yyyy-MM-ddTHH:mm:sszzz"); s = a.convertFromNeutral(s, "date", "short_date"); document.write(s);}</script> 
      </td> 
      </tr> 
      <tr> 
      <th width="12%" colspan="6">Indent Level</th> 
      <th width="5%">Part Number</th> 
      <th width="13%">Manufacturer</th> 
      <th width="13%">Manufacturer Part</th> 
      <th width="13%">Document Number</th> 
      <th width="13%">Document Name</th> 
      <th width="13%">Document Rev</th> 
      <th width="8%">Pos AML</th> 
      <th width="8%">Pos Doc</th> 
      <th width="8%">Mod</th> 
      </tr> 
      <xsl:apply-templates select="//Item[@type='Part']"></xsl:apply-templates> 
     </table> 
     </body> 
     <script src="../../javascript/PopupMenu.js"></script> 
     <script src="../../javascript/PopupMenu.js"></script> 
     <script src="../../javascript/PopupMenu.js"></script> 
     <script src="../../javascript/PopupMenu.js"></script> 
    </html> 
    </xsl:template> 
    <xsl:template match="Item[@type='Part']"> 

    <xsl:variable name="AmlItems" select="Relationships/Item[@type='Part AML']"/> 
    <xsl:variable name="DocItems" select="Relationships/Item[@type='Part Document']"/> 

    <xsl:variable name="MoreAmlItems" select="count($AmlItems) > count($DocItems)" /> 

    <xsl:variable name="largerGroup" select="$AmlItems[$MoreAmlItems] | $DocItems[not($MoreAmlItems)]" /> 

    <!-- Ensure rowCount is at least 1 --> 
    <xsl:variable name="rowCount" select="count($largerGroup) + (count($largerGroup) = 0)"/> 

    <!-- Grab values --> 
    <tr> 
     <xsl:call-template name="IndentLevel"> 
     <xsl:with-param name="rowSpan" select="$rowCount" /> 
     </xsl:call-template> 
     <td rowspan="{$rowCount}" align="center" uniqueID="ms__id16"> 
     <xsl:value-of select="item_number"></xsl:value-of> 
     </td> 
     <xsl:apply-templates select="$largerGroup[1]" /> 
     <td rowspan="{$rowCount}" align="center" uniqueID="ms__id37"> 
     <xsl:value-of select="count($AmlItems)"></xsl:value-of> 
     </td> 
     <td rowspan="{$rowCount}" align="center" uniqueID="ms__id38"> 
     <xsl:value-of select="count($DocItems)"></xsl:value-of> 
     </td> 
     <td rowspan="{$rowCount}" align="center" uniqueID="ms__id40"> 
     <xsl:value-of select="position() mod 2 = 1"></xsl:value-of> 
     </td> 
    </tr> 

    <!-- Assing first row for AML and Doc --> 
    <xsl:apply-templates select="$largerGroup[position() > 1]"></xsl:apply-templates> 
    </xsl:template> 

    <xsl:template name="IndentLevel"> 
    <xsl:param name="level" select="0" /> 
    <xsl:param name="rowSpan" /> 

    <td rowspan="{$rowSpan}" width="2%" align="center" uniqueID="ms__id{10+$level}"> 
     <xsl:if test="count(ancestor::Item[@type = 'Part']) = $level"> 
     <xsl:value-of select="$level"/> 
     </xsl:if> 
    </td> 
    <!-- Stop when we reach 5 --> 
    <xsl:if test="$level &lt; 5"> 
     <xsl:call-template name="IndentLevel"> 
     <xsl:with-param name="level" select="$level + 1" /> 
     <xsl:with-param name="rowSpan" select="$rowSpan" /> 
     </xsl:call-template> 
    </xsl:if> 
    </xsl:template> 

    <!-- AML and Doc Rows 2+ --> 
    <xsl:template match="text()" /> 

    <xsl:template match="Item[@type = 'Part AML']"> 
    <xsl:variable name="pos" select="position()" /> 
    <xsl:variable name="isTop" select="not(preceding-sibling::Item[@type = 'Part AML'])"/> 
    <xsl:call-template name="ItemRow"> 
     <xsl:with-param name="AmlItem" select="." /> 
     <xsl:with-param name="PartDocument" select="../Item[@type = 'Part Document'][position() = $pos + not($isTop)]" /> 
     <xsl:with-param name="IsTop" select="$isTop" /> 
    </xsl:call-template> 
    </xsl:template> 

    <xsl:template match="Item[@type='Part Document']"> 
    <xsl:variable name="pos" select="position()" /> 
    <xsl:variable name="isTop" select="not(preceding-sibling::Item[@type = 'Part Document'])"/> 
    <xsl:call-template name="ItemRow"> 
     <xsl:with-param name="AmlItem" select="../Item[@type = 'Part AML'][position() = $pos + not($isTop)]" /> 
     <xsl:with-param name="PartDocument" select="." /> 
     <xsl:with-param name="IsTop" select="$isTop" /> 
    </xsl:call-template> 
    </xsl:template> 

    <xsl:template name="ItemRow"> 
    <xsl:param name="AmlItem" /> 
    <xsl:param name="PartDocument" select="_" /> 
    <xsl:param name="IsTop" /> 

    <xsl:variable name="startingId" select="26 * $IsTop + 32 * not($IsTop)" /> 

    <xsl:variable name="rowData"> 
     <cell value="{$AmlItem/related_id/Item/manufacturer/@keyed_name}" /> 
     <cell value="{$AmlItem/related_id/Item[@type='Manufacturer Part']/item_number}" /> 
     <cell value="{$PartDocument/related_id[@type='Document']/Item/item_number}" /> 
     <cell value="{$PartDocument/related_id[@type='Document']/Item/name}" /> 
     <cell value="{$PartDocument/related_id[@type='Document']/Item/major_rev}" /> 
    </xsl:variable> 

    <xsl:variable name="rowCells"> 
     <xsl:call-template name="RowCells"> 
     <xsl:with-param name="rowData" select="$rowData" /> 
     <xsl:with-param name="startingId" select="$startingId" /> 
     </xsl:call-template> 
    </xsl:variable> 
    <xsl:choose> 
     <xsl:when test="$IsTop"> 
     <xsl:copy-of select="$rowCells"/> 
     </xsl:when> 
     <xsl:otherwise> 
     <tr> 
      <xsl:copy-of select="$rowCells"/> 
     </tr> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

    <xsl:template name="RowCells"> 
    <xsl:param name="rowData" /> 
    <xsl:param name="startingId" /> 

    <xsl:for-each select="msxsl:node-set($rowData)/cell"> 
     <td align="center" uniqueID="ms__id{$startingId + position() - 1}"> 
     <xsl:value-of select="@value"/> 
     </td> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

如果您正在使用非微软的XSLT处理器,您需要按照此页面上的表到msxsl命名空间更改为其他: http://www.xml.com/pub/a/2003/07/16/nodeset.html

您的源XML与输出之间似乎存在不一致。第一个项目中的<related_id>没有type属性,因此您的[@ type ='Manufacturer Part']过滤器将无法找到任何东西。那里是否应该有一个type属性?

+0

JLRishe谢谢你的帮助,我真的很感激。这对于文档非常有效。我上传了更多信息来展示整个图片。我正在使用Microsoft XSLT。我过去试图解决这个问题的方法是需要识别制造零件,以便抓住正确的item_number。目前,如果树中有多个AML元素,它看起来没有得到任何AML数据。有想法该怎么解决这个吗?谢谢你的帮助。 – user1618044

+0

好吧,所以你想要以下内容:部分AML没有部分文件后立即 - 只显示部分AML信息;部分AML和部分文件紧随其后 - 同时显示;零件文件不包含零件AML - 仅显示零件文件信息。这是全部吗?如果是这样,请尝试上述(修改)。 – JLRishe

+0

如果AML和Document都存在,我希望它们在同一行上。其他则是完美的。感谢您的帮助。 – user1618044

0

在你的第一个模板,我会改变它像这样。

<xsl:template match="Item[@type='Part AML']|Item[@type='Part Document']"> 
    <tr> 
    <xsl:apply-templates select="related_id/Item/manufacturer/@keyed_name"/> 
    ... 
    </tr> 
</xsl:template> 

这应该建立你想要的行。

+0

Matthew,谢谢你的帮助。它现在进入id_33和id_34之间的一行。有想法该怎么解决这个吗?谢谢 – user1618044

+0

它看起来像是由''模板''匹配造成的。我将不得不近距离看这个。你如何确定哪个“Part AML”与哪个“Part Document”一起使用? –

+0

它们是随机的。这一切都取决于部分。一些零件具有反洗钱(批准的制造零件)和文件。有的只有AML,有的只有文件。所以这就是我的大部分麻烦都与它的动态性有关。完整的树看起来像Item [@ type ='Part']/Relationship/Item [@ type ='Part AML']。你想让我发布整个样式表还是更多数据?谢谢 – user1618044