473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with transforming XML document

Hi,
I need help with transforming XML document.

I generate xml document from query using Oracle XSU (DBMS_XMLQUERY)
and the document I get is like this:

<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<MultiPAT>
<PAT>
<numreferencia>000000000000</numreferencia>
<tipo>1</tipo>
<trabajador>
<trabajador_row num="1">
<apellido>Rius</apellido>
<nombre>Jaume</nombre>
<naf null="YES"/>
<antiguedad>
<antiguedad_row num="1">
<meses>15</meses>
<dias>0</dias>
</antiguedad_row>
</antiguedad>
<atep null="YES"/>
<domicilio>CL.Barcelona, 27</domicilio>
<telefono null="YES"/>
</trabajador_row>
</trabajador>
</PAT>
</MultiPAT>

The problem is that the tags like <trabajador_row num="1"> are
redundant and I'd also like to eliminate attributes null="YES" (that
can be found within empty tags).
I'd like to get something like this:

<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<MultiPAT>
<PAT>
<numreferencia>000000000000</numreferencia>
<tipo>1</tipo>
<trabajador>
<apellido>Rius</apellido>
<nombre>Jaume</nombre>
<naf/>
<antiguedad>
<meses>15</meses>
<dias>0</dias>
</antiguedad>
<atep/>
<domicilio>CL.Barcelona, 27</domicilio>
<telefono/>
</trabajador>
</PAT>
</MultiPAT>

Any ideas how to do transformation?

Thanks!
Jul 20 '05 #1
2 1780
In article <a6**************************@posting.google.com >,
Mirjana Rakuljic <mi****@yahoo.com> wrote:

% I need help with transforming XML document.

[very clear description of problem elided]

% <trabajador>
% <trabajador_row num="1">

[...]

% The problem is that the tags like <trabajador_row num="1"> are
% redundant and I'd also like to eliminate attributes null="YES" (that
% can be found within empty tags).

[...]

% Any ideas how to do transformation?

Build the transformation around the so-called `identity transform'.

<xsl:transform match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:copy>
</xsl:transform>

This matches every node and every attribute node. The attribute nodes
have to be specified separately because the attribute axis isn't
searched by default.

You then specify transformations for the specific nodes you want to
handle specially. Because of the nature of the pattern match, the
identity transform is assigned a lower priority than a more specific
transform.

<xsl:transform match="trabajador/trabajador_row">
<xsl:apply-templates select="node()"/>
</xsl:transform>

That will copy the non-attribute children of trabajador_row, without
copying the trabajador_row element. I leave out the attributes because
you don't seem to like them, but you could put more detailed selection
criteria in place if you need more specific selection criteria on the
attribute side. If you have a lot of data and prepared to forget about
your null='yes' requirement, you could replace `apply-templates'
with `copy-of', which is likely to be a bit faster.

It's worth learning about xpath, incidentally. For one thing, you
really need to know about it if you want to use xslt, and for another,
it's fairly well-designed, and the spec is relatively well-written, so
you don't have to invest too much effort on it.

To get rid of the null="yes" attributes, you could do this:

<xsl:transform match="*[@null='YES']">
<xsl:copy/>
</xsl:transform>

since they're always empty, there's no need to apply any further templates.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2
Thank you very much for your help!!!!
Jul 20 '05 #3

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

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
33
by: Joe | last post by:
I'm designing a company website. I'm relatively new to CSS and I'm having trouble creating what seems to me a very simple design: - body background: fixed full page image - banner: fixed, 100...
4
by: Showjumper | last post by:
I am using the NITF DTD for my xml files and i need to use 2 xsl files to do the transform: one for the <body.head> and the second for the <body.content>. I've got this so far for transforming...
5
by: Jiho Han | last post by:
I do a transform of an xml document into another xml using XslTransform. In my xsl file, I specify using <xsl:output encoding="utf-8"/>. However, when my transform is done, the resulting xml is in...
4
by: Cathie | last post by:
Hi All, I am trying to get my style sheet to work. It works fine in IE but I can't get it to work in .net. Below is the function I use for transforming, where advancedOptionsFile is the path...
1
by: MaggotChild | last post by:
Hi, I'm trying to transform the values entered into a form: HTML: <div id="container"> <div id="bs"> <input id="name" type="text"/> <p>PPPPP</p> <a href="#" onclick="return transform()">Do...
1
by: garey | last post by:
Here are two URLs http://library11.berkeley.edu/~gmills/binds_result.xml http://library11.berkeley.edu:8080/noidbind/binds_result.xml In Firefox 2, the first URL results in the XSL...
1
by: scmorgan | last post by:
Hi All, I am trying to come up with a solution for transforming a complex type ie xml ... <document> <label> This is a <highlight> string</highlight> </label>
10
by: Mauro | last post by:
I'm trying to use the following VB function to transform a pdf document to a tiff one: http://forums.microsoft.com/msdn/showpost.aspx?postid=1665127&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=1 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.