Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Unable to traverse back in xslt

$
0
0

Hi,

I have an issue; I know that we cannot traverse back in xslt. The problem is.

I have the sample xml like this.

<SalesInvoices>
 <Invoice>
  <NumberOfEntries>1367</NumberOfEntries>
  <InvoiceNo>232</InvoiceNo>
  <InvoiceStatus>N</InvoiceStatus>
  <InvoiceStatusDate>2013-07-01 14:56:40</InvoiceStatusDate>
  <Line>
   <LineNumber>10</LineNumber>
   <OrderDate>2013-07-01</OrderDate>
   <ProductCode>10000000083320</ProductCode>
   <ProductDescription>TYVERB 250MG X 140 COMP (FRASCO)</ProductDescription>
  </Line>
  <Line>
   <LineNumber>11</LineNumber>
   <OrderDate>2013-07-01</OrderDate>
   <ProductCode>10000000033444</ProductCode>
   <ProductDescription>Dolo 200mg</ProductDescription>
  </Line>
  <Quantity>2</Quantity>
  <Description>TYVERB 250MG</Description>
  <WitholdingTax>20</WitholdingTax>
 </Invoice>
 <Invoice>
  <NumberOfEntries>1443</NumberOfEntries>
  <InvoiceNo>345</InvoiceNo>
  <InvoiceStatus>A</InvoiceStatus>
  <InvoiceStatusDate>2013-08-22 10:22:40</InvoiceStatusDate>
  <Line>
   <LineNumber>3</LineNumber>
   <OrderDate>2013-08-22</OrderDate>
   <ProductCode>10000000056756</ProductCode>
   <ProductDescription>AUGMENTIN 875/125MGX16 COM</ProductDescription>
  </Line>
  <Line>
   <LineNumber>4</LineNumber>
   <OrderDate>2013-08-22</OrderDate>
   <ProductCode>10000000056443</ProductCode>
   <ProductDescription>AUENDSIN 20 ml</ProductDescription>
  </Line>
  <Quantity>4</Quantity>
  <Description>CARTIA 2.0</Description>
  <WitholdingTax>15</WitholdingTax>
 </Invoice>
</SalesInvoices>

In this, for each invoice parent element there are 2 child Line element sets; this scenario repeats for each invoice set of elements. I get the raw data in xml like -

<XmlContent><SalesInvoices2><NewDataSet>
  <Table>
    <F1>Id#</F1>
    <F2>NumberOfEntries</F2>
    <F3>InvoiceNo</F3>
    <F4>InvoiceStatus</F4>
    <F5>InvoiceStatusDate</F5>
    <F6>LineNumber</F6>
    <F7>OrderDate</F7>
    <F8>ProductCode</F8>
    <F9>ProductDescription</F9>
    <F10>Quantity</F10>
    <F11>Description</F11>
    <F12>WitholdingTax</F12>
  </Table>
 <Table>
    <F1>1</F1>
    <F2>1367</F2>
    <F3>232</F3>
    <F4>N</F4>
    <F5>2013-07-01 14:56:40</F5>
    <F6>10</F6>
    <F7>2013-07-01</F7>
    <F8>10000000083320</F8>
    <F9>TYVERB 250MG X 140 COMP (FRASCO)</F9>
    <F10>2</F10>
    <F11>TYVERB 250MG</F11>
    <F12>20</F12>
  </Table>
<Table>
    <F1>2</F1>
    <F2>1367</F2>
    <F3>232</F3>
    <F4>N</F4>
    <F5>2013-07-01 14:56:40</F5>
    <F6>11</F6>
    <F7>2013-07-01</F7>
    <F8>10000000033444</F8>
    <F9>Dolo 200mg</F9>
    <F10>2</F10>
    <F11>TYVERB 250MG</F11>
    <F12>20</F12>
  </Table>
<Table>
    <F1>3</F1>
    <F2>1443</F2>
    <F3>345</F3>
    <F4>A</F4>
    <F5>2013-08-22 10:22:40</F5>
    <F6>3</F6>
    <F7>2013-08-22</F7>
    <F8>10000000056756</F8>
    <F9>AUGMENTIN 875/125MGX16 COM</F9>
    <F10>4</F10>
    <F11>CARTIA 2.0</F11>
    <F12>15</F12>
  </Table>
 <Table>
    <F1>4</F1>
    <F2>1443</F2>
    <F3>345</F3>
    <F4>A</F4>
    <F5>2013-08-22 10:22:40</F5>
    <F6>4</F6>
    <F7>2013-08-22</F7>
    <F8>10000000056443</F8>
    <F9>AUENDSIN 20 ml</F9>
    <F10>4</F10>
    <F11>CARTIA 2.0</F11>
    <F12>15</F12>
  </Table>
</NewDataSet></SalesInvoices2></XmlContent>

I need to convert the above XML to the format that I had mentioned in the sample; where within each Invoice the Line set of elements repeats. I am not able to arrive at a logic in the xslt; could you please let me know if this is possible.

I tried the following in the XSLT; but I am not able to create 2 sub child set of Line elements for each Invoice; this creates one set of Invoice for each record; I am not sure if I can arrive at the expected logic as per the sample xml in the xslt. This a very critical situation for me, any advice on this will be of much help. Thanks. 

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />


  <xsl:template match="/">
    <Return>
      <xsl:apply-templates select="XmlContent/SalesInvoices2/NewDataSet"/>
    </Return>
  </xsl:template>

  <xsl:template match="Table">  
    <SalesInvoices>  
        <NumberOfEntries>
          <xsl:value-of select="F2"/>
        </NumberOfEntries>
        <InvoiceNo>
          <xsl:value-of select="F3"/>
        </InvoiceNo>
        <InvoiceStatus>
          <xsl:value-of select="F4"/>
        </InvoiceStatus>      
        <InvoiceStatusDate>
          <xsl:value-of select="F5"/>
        </InvoiceStatusDate>
        <LineNumber>
          <xsl:value-of select="F6"/>
        </LineNumber>
        <OrderDate>
          <xsl:value-of select="F7"/>
        </OrderDate>
        <ProductCode>
          <xsl:value-of select="F8"/>
        </ProductCode>
        <ProductDescription>
          <xsl:value-of select="F9"/>
        </ProductDescription>
        <Quantity>
          <xsl:value-of select="F10"/>
        </Quantity>
      <Description>
          <xsl:value-of select="F11"/>
        </Description>
        <WitholdingTax>
          <xsl:value-of select="F12"/>
        </WitholdingTax>
      </SalesInvoices>   
  </xsl:template>

</xsl:stylesheet>


Rpaul


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>