2010-08-20 9 views
8

Nuevo chico aquí así que tengan paciencia conmigo. Tengo un archivo XSL básico que leerá mis datos xml. Estoy tratando de poner xml en Excel. Aquí está mi problema. Con un pequeño archivo XML parece convertirlo fácilmente, PERO con este archivo XML que tenía varios nodos (creo que se llaman), cuando llamo los datos, no está bien. Solo quiero mostrar información de la porción de verificación de XML y luego mostrarla en Excel de una manera que muestre las 6 o 7 columnas que quiero, y luego mostrar los datos. Esto es lo que tengo hasta ahora:XSL Tomando XML transformándolo en Excel

XML:

<bdiData> 
    <documentControlInfo> 
    <documentInfo> 
     <docDescription>Checks for Company X</docDescription> 
     <docID> 
     <ID>123456789</ID> 
     </docID> 
     <docModifier>My Company</docModifier> 
     <docCreateDate>2010-08-23</docCreateDate> 
     <docCreateTime>07:08:54-0700</docCreateTime> 
     <standardVersion>1.0</standardVersion> 
     <testIndicator>0</testIndicator> 
     <resendIndicator>0</resendIndicator> 
    </documentInfo> 
    <sourceInfo> 
     <sourceName>My Banking Name</sourceName> 
     <sourceID> 
     <idOther>ShortBankName</idOther> 
     </sourceID> 
    </sourceInfo> 
    <destinationInfo> 
     <destinationName>My Company</destinationName> 
     <destinationID> 
     <idOther>MYCO</idOther> 
     </destinationID> 
    </destinationInfo> 
    </documentControlInfo> 
    <checkItemCollection> 
    <collectionInfo> 
     <description>Items</description> 
     <ID>654811650</ID> 
     <Classification> 
     <classification>Items</classification> 
     </Classification> 
    </collectionInfo> 
    <checkItemBatch> 
     <checkItemBatchInfo> 
     <description>Paid Checks</description> 
     <ID>1239668334710</ID> 
     <Classification> 
      <classification>Paid Checks</classification> 
     </Classification> 
     </checkItemBatchInfo> 
     <checkItem> 
     <checkItemType>check</checkItemType> 
     <checkAmount>2960</checkAmount> 
     <postingInfo> 
      <date>2009-06-12</date> 
      <RT>87654321</RT> 
      <accountNumber>123465798</accountNumber> 
      <seqNum>007725552898</seqNum> 
      <trancode>001152</trancode> 
      <amount>2960</amount> 
      <serialNumber>55225410</serialNumber> 
     </postingInfo> 

XSL del archivo:

<xsl:stylesheet version="1.0" 
    xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:user="urn:my-scripts" 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" > 

    <xsl:template match="/"> 
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
     xmlns:o="urn:schemas-microsoft-com:office:office" 
     xmlns:x="urn:schemas-microsoft-com:office:excel" 
     xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
     xmlns:html="http://www.w3.org/TR/REC-html40"> 
     <xsl:apply-templates/> 
    </Workbook> 
    </xsl:template> 


    <xsl:template match="/*"> 
    <Worksheet> 
     <xsl:attribute name="ss:Name"> 
     <xsl:value-of select="local-name(/*/*)"/> 
     </xsl:attribute> 
     <Table x:FullColumns="1" x:FullRows="1"> 
     <Row> 

      <xsl:for-each select="*[position() = 2]/*/checkItem/postingInfo/*"> 

      <Cell> 
       <Data ss:Type="String"> 
       <xsl:value-of select="local-name()"/> 
       </Data> 
      </Cell> 
      </xsl:for-each> 
     </Row> 
     <xsl:apply-templates/> 
     </Table> 
    </Worksheet> 
    </xsl:template> 


    <xsl:template match="/*/checkItem/postingInfo/*"> 
    <Row> 
     <xsl:apply-templates/> 
    </Row> 
    </xsl:template> 


    <xsl:template match="/*/checkItem/postingInfo/*"> 
    <Cell> 
     <Data ss:Type="String"> 
     <xsl:value-of select="."/> 
     </Data> 
    </Cell> 
    </xsl:template> 


</xsl:stylesheet> 

¿Alguien tiene alguna idea de cómo puedo llegar a sólo la parte de comprobación f el archivo XML y tienen formatear de una manera eay?

Gracias

GabrielVA

+0

¿Se puede publicar el XML real con las etiquetas? – InSane

Respuesta

9

Creo que se necesita esta hoja de estilo:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:x="urn:schemas-microsoft-com:office:excel"> 
    <xsl:template match="/"> 
     <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction> 
     <Workbook> 
      <xsl:apply-templates/> 
     </Workbook> 
    </xsl:template> 
    <xsl:template match="/*"> 
     <Worksheet ss:Name="{*/*/*[local-name()='docDescription']}"> 
      <Table x:FullColumns="1" x:FullRows="1"> 
       <Row> 
        <xsl:for-each select="*/*/*[local-name()='checkItem'][1]//*[not(*)]"> 
         <Cell> 
          <Data ss:Type="String"> 
           <xsl:value-of select="local-name()"/> 
          </Data> 
         </Cell> 
        </xsl:for-each> 
       </Row> 
       <xsl:apply-templates select="*/*/*[local-name()='checkItem']"/> 
      </Table> 
     </Worksheet> 
    </xsl:template> 
    <xsl:template match="*[local-name()='checkItem']" priority="1"> 
     <Row> 
      <xsl:apply-templates select=".//*[not(*)]"/> 
     </Row> 
    </xsl:template> 
    <xsl:template match="*[not(*)]"> 
     <Cell> 
      <Data ss:Type="String"> 
       <xsl:value-of select="."/> 
      </Data> 
     </Cell> 
    </xsl:template> 
</xsl:stylesheet> 

Con esta entrada (adecuada bien formado):

<bdiData> 
    <documentControlInfo> 
     <documentInfo> 
      <docDescription>Checks for Company X</docDescription> 
      <docID> 
       <ID>123456789</ID> 
      </docID> 
      <docModifier>My Company</docModifier> 
      <docCreateDate>2010-08-23</docCreateDate> 
      <docCreateTime>07:08:54-0700</docCreateTime> 
      <standardVersion>1.0</standardVersion> 
      <testIndicator>0</testIndicator> 
      <resendIndicator>0</resendIndicator> 
     </documentInfo> 
     <sourceInfo> 
      <sourceName>My Banking Name</sourceName> 
      <sourceID> 
       <idOther>ShortBankName</idOther> 
      </sourceID> 
     </sourceInfo> 
     <destinationInfo> 
      <destinationName>My Company</destinationName> 
      <destinationID> 
       <idOther>MYCO</idOther> 
      </destinationID> 
     </destinationInfo> 
    </documentControlInfo> 
    <checkItemCollection> 
     <collectionInfo> 
      <description>Items</description> 
      <ID>654811650</ID> 
      <Classification> 
       <classification>Items</classification> 
      </Classification> 
     </collectionInfo> 
     <checkItemBatch> 
      <checkItemBatchInfo> 
       <description>Paid Checks</description> 
       <ID>1239668334710</ID> 
       <Classification> 
        <classification>Paid Checks</classification> 
       </Classification> 
      </checkItemBatchInfo> 
      <checkItem> 
       <checkItemType>check</checkItemType> 
       <checkAmount>2960</checkAmount> 
       <postingInfo> 
        <date>2009-06-12</date> 
        <RT>87654321</RT> 
        <accountNumber>123465798</accountNumber> 
        <seqNum>007725552898</seqNum> 
        <trancode>001152</trancode> 
        <amount>2960</amount> 
        <serialNumber>55225410</serialNumber> 
       </postingInfo> 
      </checkItem> 
     </checkItemBatch> 
    </checkItemCollection> 
</bdiData> 

Salida:

<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel"> 
    <Worksheet ss:Name="Checks for Company X"> 
     <Table x:FullColumns="1" x:FullRows="1"> 
      <Row> 
       <Cell> 
        <Data ss:Type="String">checkItemType</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">checkAmount</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">date</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">RT</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">accountNumber</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">seqNum</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">trancode</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">amount</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">serialNumber</Data> 
       </Cell> 
      </Row> 
      <Row> 
       <Cell> 
        <Data ss:Type="String">check</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">2960</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">2009-06-12</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">87654321</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">123465798</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">007725552898</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">001152</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">2960</Data> 
       </Cell> 
       <Cell> 
        <Data ss:Type="String">55225410</Data> 
       </Cell> 
      </Row> 
     </Table> 
    </Worksheet> 
</Workbook> 

Bien abierto por Excel.

Nota: esos fn:local-name() existen porque la muestra de entrada no es confiable.