473,657 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generic xslt to nest a xml-document as text within an element

Hallo,

can you help me writing a generic xslt transformation (useable with
xsql from oracle)? The problem is how to get the escaping characters
....

=== INPUT-File in.xml
<?xml version = '1.0'?>
<person><who>sc ott</who></person>

=== Needed OUTPUT-File out.xml
=== Note: the format must be exactly this to be
=== processable by xsql using xsql-insert
<?xml version = '1.0'?>
<ROWSET><ROW>
<NAME>&lt;perso n>&lt;who>scott &lt;/who>&lt;/person></NAME>
</ROW></ROWSET>

=== My xslt-File p.xsl, that misses the important fact
=== of replacing < with &lt;
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="ye s"/>
<xsl:template match="@*|node( )">
<xsl:element name="ROWSET">
<xsl:element name="ROW">
<xsl:element name="NAME">
<xsl:copy-of select="."/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

=== my output, that is not the expected
oraxsl in.xml p.xsl
<ROWSET><ROW><N AME><person><wh o>scott</who></person></NAME></ROW></ROWSET>

Any ideas?
Thank you if you find the time for helping,
Martin
Jul 20 '05 #1
2 3127
In article <10************ **************@ posting.google. com>,
Martin <ms*****@csc.co m> wrote:

% === INPUT-File in.xml
% <?xml version = '1.0'?>
% <person><who>sc ott</who></person>
%
% === Needed OUTPUT-File out.xml
% === Note: the format must be exactly this to be
% === processable by xsql using xsql-insert
% <?xml version = '1.0'?>
% <ROWSET><ROW>
% <NAME>&lt;perso n>&lt;who>scott &lt;/who>&lt;/person></NAME>
% </ROW></ROWSET>

% === My xslt-File p.xsl, that misses the important fact
% === of replacing < with &lt;
% <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
% version="1.0">
% <xsl:output method="xml" omit-xml-declaration="ye s"/>
% <xsl:template match="@*|node( )">
% <xsl:element name="ROWSET">
% <xsl:element name="ROW">
% <xsl:element name="NAME">
% <xsl:copy-of select="."/>
% </xsl:element>
% </xsl:element>
% </xsl:element>
% </xsl:template>
% </xsl:stylesheet>

You should keep in mind that the output of the XSLT process is a tree,
not just text. When you use copy-of, what you're doing is copying the
tree structure related to the node, not the tags themselves.
So, how do you get the tags? Probably node-by-node, using the name()
function. If all you want is a copy of the original document with
< and & escaped, I'm not sure XSLT is the best thing to use, but
let's have an untested go at it

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="ye s"/>

<!-- need to handle elements, pis, comments, and attributes separately
since we need to format the tags. We start with elements -->
<xsl:template match="*">
<!-- no need for xsl:element here, so let's not use it -->
<ROWSET>
<ROW>
<NAME>
<xsl:text>&lt ;</xsl:text>
<xsl:value-of select="name()"/>

<!-- attributes go here -->
<xsl:for-each select="@*">
<xsl:value-of select='name()'/.
<xsl:text>='</xsl:text>
<!-- you might need to deal with quotes here -->
<xsl:value-of select='.'/.
<xsl:text>'</xsl:text>
</xsl:for-each>
<xsl:text>&gt ;</xsl:text>

<xsl:apply-templates/>

<xsl:text>&lt ;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt ;</xsl:text>
</NAME>
</ROW>
</ROWSET>
</xsl:template>

<xsl:template match="processi ng-instruction()">
<xsl:text>&lt;? </xsl:text>
<xsl:value-of select='name()'/>
<xsl:text> </xsl:text>
<xsl:value-of select='.'/>
<xsl:text>?&gt; </xsl:text>
</xsl:template>

<xsl:template match="comment( )">
<xsl:text>&lt ;-- </xsl:text>
<xsl:value-of select='.'/>
<xsl:text> --&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #2
Hallo Patrick,

for an untested go your answer was really excellent.
I've found (after quite some more study of xsl/xpath) a solution,
but comparing it with your solution i got to know the
difference between a beginner and an expert (simply because my
solution was neither elegant, nor did I cover points like
comment-nodes or processing instructions).

A big thank you for your answer!

For other readers: see the finished solution below ...

Greetings from vienna,
Martin

===== rowset_row_doc. xsl
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />

<xsl:template match="/">
<xsl:element name="ROWSET">
<xsl:element name="ROW">
<xsl:element name="DOC">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>

<!-- need to handle elements, pis, comments, and attributes separately
since we need to format the tags. We start with elements -->
<xsl:template match="*">
<xsl:text>&lt ;</xsl:text>
<xsl:value-of select="name()"/>

<!-- attributes go here -->
<xsl:for-each select="@*">
<xsl:text> </xsl:text>
<xsl:value-of select='name()'/>
<xsl:text>="</xsl:text>
<!-- Assumption: input file has not apostrophs -->
<xsl:value-of select='.'/>
<xsl:text>"</xsl:text>
</xsl:for-each>
<xsl:text>&gt ;</xsl:text>

<xsl:apply-templates/>

<xsl:text>&lt ;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt ;</xsl:text>
</xsl:template>

<xsl:template match="processi ng-instruction()">
<xsl:text>&lt;? </xsl:text>
<xsl:value-of select='name()'/>
<xsl:text> </xsl:text>
<xsl:value-of select='.'/>
<xsl:text>?&gt; </xsl:text>
</xsl:template>

<xsl:template match="comment( )">
<xsl:text>&lt ;-- </xsl:text>
<xsl:value-of select='.'/>
<xsl:text> --&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
===== output from above sample
C:\XDK>oraxsl in.xml rowset_row_doc. xsl
<?xml version = '1.0'?>
<ROWSET><ROW><D OC>&lt;person>& lt;who>scott&lt ;/who>&lt;/person></DOC></ROW></ROWSET>
Jul 20 '05 #3

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

Similar topics

9
4159
by: Hayko Riemenschneider | last post by:
Hi! I've got me an XSL tranformation stylesheet for my XML file. In the XSL file I now wish to use PHP to do some scripting. So I thought I'll use the PIs like this: <xsl:processing-instruction name="php"> echo $hello; </xsl:processing-instruction>
6
2909
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
1
3598
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by version 2 of XSLT processor based on some condition. Q) How and where shall I write logic or import desirable XSLT on the Fly ? Q) When we call AAA.XSLT then it will be processed by XSLT Processor 1
8
2142
by: Timothy Casey | last post by:
Is there any way to code an external style sheet to ensure that all pages opening with a reference to that style sheet include generic content such as headers, logos, taglines, universal navigation links, etc...? While limiting the unique content of the page making the external style sheet reference to a relatively sized cell that includes a scrollbar when the content overflows the bounds of the cell...? Thanks in Advance...
3
2251
by: Jack Fox | last post by:
I've never had the need to work with XML, but I believe I now have an appropriate application. I have time-series data in objects organized as a tree that I want an ASP.NET program to write out to web pages formatted as a matrix. It is not a simple matrix, since the number of row heading cells can vary, but the data cells must be aligned by date (so the heading cells will not be uniformly sized). example of typical rows: 3 heading...
0
1779
by: Brendan Reynolds | last post by:
I have a web service that takes the XML representation of a dataset and uses XSLT to transform it to the format required to open a disconnected ADODB recordset on the XML, and returns the transformed XML as a string, for use in an Access/VBA application. The transformed XML looks, in part, like this .... <z:row AbsenceDate="2004-06-01T00:00:00.0000000+01:00" TeacherCode="davolio" ClassCode="Junior Infants" StudentCode="Ana Trujillo"...
1
1202
by: womber | last post by:
What do you think is the best design approach when your trying to get nested XML results from dataSet.GetXML. Define the relations in the dataset or apply an XSLT stylesheet to nest the results by syncing the dataset with an XMLdocument?
6
3233
by: Christopher | last post by:
I am currently in the process of evaluating the performance hits of moving to the .NET platform for our application. I created a sample project that loads the transforms the same XML and XSLT in COM, COM using interop and in C# and then transforms it to HTML. I also tried concatenating the XML and XSL as a string and then loading it to the DOM once as opposed to loading the DOM with the appendChild() method. I see that the C# version is...
3
1267
by: Jensen bredal | last post by:
Hello, I need to write different kind of forms that the customer can use to enter data and save the data into database. (The data access will be hand coded) My problem is that the form may vary . I therefore need an engine , that can produce the form based on let say an xml file. The form may contain textboxes, buttons , labels , pictures etc...
2
2134
by: veracon | last post by:
Hello, I'm looking to use XML and XSLT for templates in a system I'm writing, however I'm not really sure which parser is the "best". Basically, which library has the most features, and which is the most supported? A guide I saw mentioned importing xml.xslt, however it appears the xml module/package contains pretty much nothing - xml.xslt outputs an exception, No module named xslt.
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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
8612
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...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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
4171
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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 we have to send another system
2
1969
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.