Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

create text file from xml file - full xslt needed please

https://www.experts-exchange.com
 
Hi
 
I have the following XML file that I need to extract the data out of into text format (a line for each entire )for each <ReturnedDebitItem> node, can someone help with the XSLT please?
 
I'm ok with the very basics and currently use the following batch file and xalan.jar, xercesImpl.jar and xmlParserAPIs.jar called with the following batch file:
 

convert.bat
-----------
 
echo off
 
if not exist .\build-listed-buildings.bat goto ERROR
set CP=.\xalan.jar;.\xmlParserAPIs.jar;.\xercesImpl.jar
echo on
 
java -cp %CP% org.apache.xalan.xslt.Process -IN .\sd_arudd_270707.xml -XSL .\sd_arudd.xsl -OUT .\result.txt
 
echo off
goto END
 
:ERROR
echo This 'bat' file can only run from the root of the folder -- please 'cdir' to this folder then try again
goto END
 
:END
pause
echo on
 
 
 
--------------------------------------
 
<?xml version="1.0" encoding="UTF-8"?>
<BACSDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newbacs-advices.xsd">
  <Data>
    <ARUDD>
      <Header reportType="abc123" adviceNumber="123" currentProcessingDate="2007-07-27"></Header>
      <AddresseeInformation name="test"></AddresseeInformation>
      <ServiceLicenseInformation userName="test" userNumber="123"></ServiceLicenseInformation>
      <Advice>
        <OriginatingAccountRecords>
          <OriginatingAccountRecord>
            <OriginatingAccount name="ABC HHGGDD P" number="22334455" sortCode="00-00-00" type="0" bankName="My Bank" branchName="High ROAD"></OriginatingAccount>
            <ReturnedDebitItem ref="PAR123            " transCode="66" returnCode="333" returnDescription="asdsad" originalProcessingDate="2007-07-25" valueOf="25.00" currency="GBP"><PayerAccount number="12345678" ref="P00531            " name="asdfg &amp; dsfsdf" sortCode="01-01-01" bankName="My Bank 1" branchName="HIGH STREET"></PayerAccount></ReturnedDebitItem>
            <ReturnedDebitItem ref="PAR123            " transCode="77" returnCode="444" returnDescription="asdasd" originalProcessingDate="2007-07-25" valueOf="75.00" currency="GBP"><PayerAccount number="87654321" ref="P00674            " name="zxccxz &amp; dsfsdf" sortCode="02-02-02" bankName="My Bank 2" branchName="LOW STREET"></PayerAccount></ReturnedDebitItem>
            <Totals numberOf="2" valueOf="100..00" currency="GBP"></Totals>
          </OriginatingAccountRecord>
        </OriginatingAccountRecords>
      </Advice>
    </ARUDD>
  </Data>
  <SignatureMethod></SignatureMethod>
  <Signature></Signature>
</BACSDocument>
 
Avatar of R7AF
R7AF
Flag of Netherlands image

Try this:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
      <xsl:output method="text" indent="no" />

<xsl:template match="ReturnedDebitItem">
      <xsl:for-each select="@*">
            <xsl:value-of select="." /><xsl:text> </xsl:text>
      </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
Avatar of Neil Thompson

ASKER

superb but i forgot to say i need to add extra bits and remove others, how would I grab the parts of each of these repeating elements?

neil
ASKER CERTIFIED SOLUTION
Avatar of R7AF
R7AF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Superb, very clear thank  you

Neil