473,473 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML to (simple) custom defined output

Hello,

I am not a stylesheet designer, but I am wondering if (and how) the
following XML file can be transformed to a custom defined text output file.

from XML file:
<?xml version="1.0" encoding="UTF-8"?>
<BatchList>
<Header>
<SYSCODE>IOPL</SYSCODE>
<TRANDAT>020101</TRANDAT>
<WERKMY>45250</WERKMY>
<VALUTA>EUR</VALUTA>
</Header>
<Detail>
<SYSCODE>IOPL</SYSCODE>
<CODE>12547</CODE>
<LABEL1>1</LABEL1>
<BEDRA1>12</BEDRA1>
<BEDRB1>0</BEDRB1>
</Detail>
<Header>
<SYSCODE>IOPL</SYSCODE>
<TRANDAT>020101</TRANDAT>
<WERKMY>45250</WERKMY>
<VALUTA>USD</VALUTA>
</Header>
<Detail>
<SYSCODE>IOPL</SYSCODE>
<CODE>65478</CODE>
<LABEL1>1</LABEL1>
<BEDRA1>12</BEDRA1>
<BEDRB1>10</BEDRB1>
</Detail>
<Detail>
<SYSCODE>IOPL</SYSCODE>
<CODE>74784</CODE>
<LABEL1>2</LABEL1>
<BEDRA1>11</BEDRA1>
<BEDRB1>9</BEDRB1>
</Detail>
</BatchList>

To custom text file:
IOPL02010145250EUR
IOPL12547 1 12
IOPL02010145250USD
IOPL65478 1 12 10
IOPL74784 2 11 9

Any suggestions?
Thanks in advance.

Duncan
Jul 20 '05 #1
1 1676
"Duncan Bloem" <da*****@xs4all.nl> wrote in message
news:3f***********************@news.xs4all.nl
Hello,

I am not a stylesheet designer, but I am wondering if (and how) the
following XML file can be transformed to a custom defined text output
file.

[...snip...]
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:template match="Header">
<xsl:value-of select="concat(SYSCODE, TRANDAT, WERKMY, VALUTA,
' ')"/>
</xsl:template>

<xsl:template match="Detail">
<xsl:variable name="label1">
<xsl:call-template name="padd">
<xsl:with-param name="len" select="number('5') -
string-length(LABEL1)"/>
<xsl:with-param name="str" select="LABEL1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bedra1">
<xsl:call-template name="padd">
<xsl:with-param name="len" select="number('6') -
string-length(BEDRA1)"/>
<xsl:with-param name="str" select="BEDRA1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="bedrb1">
<xsl:call-template name="padd">
<xsl:with-param name="len" select="number('6') -
string-length(BEDRB1)"/>
<xsl:with-param name="str" select="BEDRB1"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(SYSCODE, CODE, $label1, $bedra1, $bedrb1,
' ')"/>
</xsl:template>

<xsl:template name="padd">
<xsl:param name="len"/>
<xsl:param name="str"/>
<xsl:if test="number($str != 0)">
<xsl:choose>
<xsl:when test="$len &gt; 0">
<xsl:call-template name="padd">
<xsl:with-param name="len" select="$len - 1"/>
<xsl:with-param name="str" select="concat(' ', $str)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

The template for "Detail" elements could be somewhat more elegant, but I
cannot think of anything better right now. :-)

The Result produced is:
IOPL02010145250EUR
IOPL12547 1 12
IOPL02010145250USD
IOPL65478 1 12 10
IOPL74784 2 11 9

That matches your wanted result, I consider your last line a typo.
IOPL02010145250EUR
IOPL12547 1 12
IOPL02010145250USD
IOPL65478 1 12 10
IOPL74784 2 11 9


I don't know if ' ' (LF) suits you as newline, take ' '
(CRLF) if you want.

Martin
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs...
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
2
by: Mrs Howl | last post by:
I have a query that just reads one table and appends to an output table, one-for-one. No criteria. It's not a Total query (i.e. no group by). It normally run run in minutes, but gets horribly...
16
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
1
by: Alex Nitulescu | last post by:
Hi. I'm creating my first custom controls. I have this code: Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) output.AddAttribute("color", )...
1
by: aspnet20vb_mike | last post by:
I have a Custom Control which inherits from GridView. I call it GridViewSort and it is in a namespace "PDS.WebControls". I add it to the Toolbox, drop it on my WebForm and it shows up and...
18
by: smnoff | last post by:
Ok, I am think I am a little more knowledgeable about C and pointers, ughh. And likewise, I want to fix C.....and not so much to make a C++ or Java or C# or even D like language. So, if I...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.