473,671 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_r ow num="1">
<apellido>Riu s</apellido>
<nombre>Jaume </nombre>
<naf null="YES"/>
<antiguedad>
<antiguedad_r ow num="1">
<meses>15</meses>
<dias>0</dias>
</antiguedad_row>
</antiguedad>
<atep null="YES"/>
<domicilio>CL.B arcelona, 27</domicilio>
<telefono null="YES"/>
</trabajador_row>
</trabajador>
</PAT>
</MultiPAT>

The problem is that the tags like <trabajador_r ow 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>Riu s</apellido>
<nombre>Jaume </nombre>
<naf/>
<antiguedad>
<meses>15</meses>
<dias>0</dias>
</antiguedad>
<atep/>
<domicilio>CL.B arcelona, 27</domicilio>
<telefono/>
</trabajador>
</PAT>
</MultiPAT>

Any ideas how to do transformation?

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

% I need help with transforming XML document.

[very clear description of problem elided]

% <trabajador>
% <trabajador_r ow num="1">

[...]

% The problem is that the tags like <trabajador_r ow 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:transfor m 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:transfor m match="trabajad or/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:transfor m 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.c om
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
2741
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 straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
33
3819
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 pixels high, full-width, transparent background - nav bar: fixed, 200 px wide, auto-height, opaque nav icons, semi-transparent tiled image background - content box: scrolling, auto height, auto width, opaque text, semi-transparent tiled image...
4
1929
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 using 1 xsl file: Dim doc As New XmlDocument doc.LoadXml(xmlText) Dim xslDoc As New XslTransform xslDoc.Load(xslpath) Dim sw As New StringWriter xslDoc.Transform(doc, Nothing, sw, Nothing)
5
4496
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 utf-16. What gives? Anyone?
4
2023
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 to the file containing an XML document required by the transformation, and xmlSimplified is the XML document to trasform. ---------------------------------------------------------------------------- -------------------------------
1
2420
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 it!</a> </div>
1
1602
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 stylesheet referenced in the XML document being applied correctly. The second URL does not. The difference is that the first URL is being served by Apache httpd 1.3.X, and the second by Tomcat 6.0. This document was generated dynamically by the app at...
1
2062
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
10349
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 Private Sub savePDFtoTIF(ByVal fullPathPDF As String, ByVal fullPathTIF As String) Dim PDFApp As Acrobat.AcroApp Dim PDDoc As Acrobat.CAcroPDDoc Dim AVDoc As Acrobat.CAcroAVDoc Dim JSObj As Object
0
8485
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8403
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6238
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.