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

Home Posts Topics Members FAQ

XML and XSLT question. Please help me out...

Hi,

First of all, hi to you all.
I'm working on a Delphi project wich is becoming near it's deadline.
I have a very simple XSLT question wich i hope one of you folks can
help me with?

The problem is i need to transform a xml file from this:

<root>
<metadata>Thi s is some metadata</metadata>
<item>
<b>some text</b>
<c>href://www.somewhere.c om?id=001</c>
</item>
<item>
<b>some other text</b>
<c>href://www.somewhere.c om?id=002</c>
</item>
</root>

to this:

<root>
<metadata>Thi s is some metadata</metadata>
<item>
<b>some text</b>
<c>href://www.somewhere.c om/?var=X&new_id=0 01</c>
</item>
<item>
<b>some other text</b>
<c>href://www.somewhere.c om/?var=X&new_id=0 02</c>
</item>
</root>

This has to be done using XSLT.
The translation from 'href://www.somewhere.c om?id=002' to
'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
using regular expressions for that. The xslt script however is a big
problem (for me that is). Can someone please help me out on this one,
there's no one at my current office who knows any XSLT.. And reading
all the online tutorials (spend one day on that) didn't help me..

Many thanks in advance,
Dennis

Oct 27 '05 #1
5 1458

The translation from 'href://www.somewhere.c om?id=002' to
'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
using regular expressions for that.


So if you're going to be using regular expressions for that, what do you
want the xslt script to do? Other than this change you indicated above,
the two trees look identical to me, and would not need any
transformation after you've done what you wanted using regular
expressions. Or am i missing something here?
Oct 27 '05 #2
hilz wrote:
The translation from 'href://www.somewhere.c om?id=002' to
'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
using regular expressions for that.


So if you're going to be using regular expressions for that, what do you
want the xslt script to do? Other than this change you indicated above,
the two trees look identical to me, and would not need any
transformation after you've done what you wanted using regular
expressions. Or am i missing something here?


Yes your missing the point that they demand it's an xslt file.
The application is alleady written, one of the demands was that it had
the option of applying an external XSLT file, this way the user of the
application had control over the XML the application outputs.
I've build this option succesfully into my application, but know
they're asking if i can deliver the app with one standard *.xsl file
wich does the above.
The problem being i know to little about XSLT.

The main problem i'm running into here is that most examples on the net
are showing you how to transform the xml entirely. They're not showing
how to keep the original xml only changing one recurring element
(item/c in this case).

I'm looking for a simple example wich does transform the provided xml,
i can than myself hack the XPATH (those are regeps right?) expressions
in the *.xsl file so it matches my client's needs.

Hope someone can help,
Dennis

Oct 27 '05 #3
dennis wrote:
hilz wrote:
The translation from 'href://www.somewhere.c om?id=002' to
'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
using regular expressions for that.


So if you're going to be using regular expressions for that, what do you
want the xslt script to do? Other than this change you indicated above,
the two trees look identical to me, and would not need any
transformatio n after you've done what you wanted using regular
expressions . Or am i missing something here?

Yes your missing the point that they demand it's an xslt file.
The application is alleady written, one of the demands was that it had
the option of applying an external XSLT file, this way the user of the
application had control over the XML the application outputs.
I've build this option succesfully into my application, but know
they're asking if i can deliver the app with one standard *.xsl file
wich does the above.
The problem being i know to little about XSLT.

The main problem i'm running into here is that most examples on the net
are showing you how to transform the xml entirely. They're not showing
how to keep the original xml only changing one recurring element
(item/c in this case).

I'm looking for a simple example wich does transform the provided xml,
i can than myself hack the XPATH (those are regeps right?) expressions
in the *.xsl file so it matches my client's needs.

Hope someone can help,
Dennis

ok here is a starting point...
you can use something like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no "
version="1.0"/>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="c">
*** here you need to output the transformed href ****
</xsl:template>

</xsl:stylesheet>


this will bascially copy all elements/attributes, except for the <c>
element, where you will need to somehow transform the old href to a new
one...
so all what you need to do is add some code in the place indicated by
this line
*** here you need to output the transformed href ****

HTH
Oct 27 '05 #4
hilz wrote:
dennis wrote:
hilz wrote:
The translation from 'href://www.somewhere.c om?id=002' to
'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
using regular expressions for that.

So if you're going to be using regular expressions for that, what do you
want the xslt script to do? Other than this change you indicated above,
the two trees look identical to me, and would not need any
transformati on after you've done what you wanted using regular
expression s. Or am i missing something here?

Yes your missing the point that they demand it's an xslt file.
The application is alleady written, one of the demands was that it had
the option of applying an external XSLT file, this way the user of the
application had control over the XML the application outputs.
I've build this option succesfully into my application, but know
they're asking if i can deliver the app with one standard *.xsl file
wich does the above.
The problem being i know to little about XSLT.

The main problem i'm running into here is that most examples on the net
are showing you how to transform the xml entirely. They're not showing
how to keep the original xml only changing one recurring element
(item/c in this case).

I'm looking for a simple example wich does transform the provided xml,
i can than myself hack the XPATH (those are regeps right?) expressions
in the *.xsl file so it matches my client's needs.

Hope someone can help,
Dennis

ok here is a starting point...
you can use something like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no "
version="1.0"/>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="c">
*** here you need to output the transformed href ****
</xsl:template>

</xsl:stylesheet>


this will bascially copy all elements/attributes, except for the <c>
element, where you will need to somehow transform the old href to a new
one...
so all what you need to do is add some code in the place indicated by
this line
*** here you need to output the transformed href ****


....which would be something like

<xsl:template match="c">
<c>
<xsl:value-of select="substri ng-before(.,'id=') "/>
<xsl:text>var=X &amp;new_id= </xsl:text>
<xsl:value-of select="substri ng-after(.,'id=')"/>
</c>
</xsl:template>

No need for any REs, just split the string and insert the new stuff.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Oct 27 '05 #5
Peter & hilz

THANK YOU !!!!!

This came in just in time, spend allmost all night reading a zillion
tutorials. I found the copy and copy-of functions but didn't get them
to work, till now that is..

Have a nice weekend and again Thanks,
Dennis

Peter Flynn wrote:
hilz wrote:
dennis wrote:
hilz wrote:

>The translation from 'href://www.somewhere.c om?id=002' to
>'href://www.somewhere.c om/?var=X&new_id=0 02' is no problem, i'll be
>using regular expressions for that.

So if you're going to be using regular expressions for that, what do you
want the xslt script to do? Other than this change you indicated above,
the two trees look identical to me, and would not need any
transformati on after you've done what you wanted using regular
expression s. Or am i missing something here?
Yes your missing the point that they demand it's an xslt file.
The application is alleady written, one of the demands was that it had
the option of applying an external XSLT file, this way the user of the
application had control over the XML the application outputs.
I've build this option succesfully into my application, but know
they're asking if i can deliver the app with one standard *.xsl file
wich does the above.
The problem being i know to little about XSLT.

The main problem i'm running into here is that most examples on the net
are showing you how to transform the xml entirely. They're not showing
how to keep the original xml only changing one recurring element
(item/c in this case).

I'm looking for a simple example wich does transform the provided xml,
i can than myself hack the XPATH (those are regeps right?) expressions
in the *.xsl file so it matches my client's needs.

Hope someone can help,
Dennis

ok here is a starting point...
you can use something like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no "
version="1.0"/>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="c">
*** here you need to output the transformed href ****
</xsl:template>

</xsl:stylesheet>


this will bascially copy all elements/attributes, except for the <c>
element, where you will need to somehow transform the old href to a new
one...
so all what you need to do is add some code in the place indicated by
this line
*** here you need to output the transformed href ****


...which would be something like

<xsl:template match="c">
<c>
<xsl:value-of select="substri ng-before(.,'id=') "/>
<xsl:text>var=X &amp;new_id= </xsl:text>
<xsl:value-of select="substri ng-after(.,'id=')"/>
</c>
</xsl:template>

No need for any REs, just split the string and insert the new stuff.

///Peter
--
XML FAQ: http://xml.silmaril.ie/


Oct 28 '05 #6

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

Similar topics

1
1459
by: David Way | last post by:
I have an xml file looks like this: <root> <L1>a</L1> <L2>b <L3>c</L3> </L2> </root> In my xslt file, I do a template match to get to <L3>
3
2117
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim is to process the contacts in a single-pass XSLT process. That is why the "document()" function is what I need. I call the "document()" XPath function from a "for-each" instruction.
1
2011
by: mountain1228 | last post by:
Hello, I apoligize in advance if this post is off-topic in this group. I have been converting xml to html with an xslt stylesheet using the program xslt-parser that comes with RH 7.3. The output mirrors that in the xslt file. The only exception are the first two lines of each file I convert to html.
0
2344
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
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...
0
3293
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections. Each section has a list of questions. Each question has responses. I need to display a list of responses to the questions (i.e. set:distinct), once and only once, each section. My second problem is that these questions can also have corrective...
18
2066
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
14
5139
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue> <SpecCat>Dimension</SpecCat> </Spec>
1
1297
by: nayijitu | last post by:
Hi, I need some thing like this. I have an XML file and it contain some elements(tag) with a proper hierarchy... In that XML a particular element <page> contain some child node element like below ..... <page> <Question></Question> <Question></Question>
0
8845
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
8743
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...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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
7355
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...
0
5647
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
4173
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
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
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

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.