create text file from xml file - full xslt needed please

Posted on 2007-07-27
Last Modified: 2013-11-18
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:

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
echo This 'bat' file can only run from the root of the folder -- please 'cdir' to this folder then try again
goto END
echo on
<?xml version="1.0" encoding="UTF-8"?>
<BACSDocument xmlns:xsi="" xsi:noNamespaceSchemaLocation="newbacs-advices.xsd">
      <Header reportType="abc123" adviceNumber="123" currentProcessingDate="2007-07-27"></Header>
      <AddresseeInformation name="test"></AddresseeInformation>
      <ServiceLicenseInformation userName="test" userNumber="123"></ServiceLicenseInformation>
            <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>
Question by:NeilT
    LVL 13

    Expert Comment

    Try this:

    <?xml version='1.0'?>

    <xsl:stylesheet xmlns:xsl=""
          xmlns: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>

    LVL 3

    Author Comment

    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?

    LVL 13

    Accepted Solution

    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>

    LVL 3

    Author Comment

    Superb, very clear thank  you


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now