Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1114
  • Last Modified:

create text file from xml file - full xslt needed please

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>
 
0
Neil Thompson
Asked:
Neil Thompson
  • 2
  • 2
1 Solution
 
R7AFCommented:
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>
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
0
 
R7AFCommented:
You can replace the for-each with value-of. And you can see if you need the <xsl:text> at all. Maybe a simple space is enough. Just try it.

<xsl:template match="ReturnedDebitItem">
    <xsl:value-of select="@ref" /><xsl:text> </xsl:text>
    <xsl:value-of select="@returnCode" /><xsl:text> </xsl:text>
</xsl:template>

etc.
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Superb, very clear thank  you

Neil
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now