469,898 Members | 1,591 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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>This is some metadata</metadata>
<item>
<b>some text</b>
<c>href://www.somewhere.com?id=001</c>
</item>
<item>
<b>some other text</b>
<c>href://www.somewhere.com?id=002</c>
</item>
</root>

to this:

<root>
<metadata>This is some metadata</metadata>
<item>
<b>some text</b>
<c>href://www.somewhere.com/?var=X&new_id=001</c>
</item>
<item>
<b>some other text</b>
<c>href://www.somewhere.com/?var=X&new_id=002</c>
</item>
</root>

This has to be done using XSLT.
The translation from 'href://www.somewhere.com?id=002' to
'href://www.somewhere.com/?var=X&new_id=002' 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 1328

The translation from 'href://www.somewhere.com?id=002' to
'href://www.somewhere.com/?var=X&new_id=002' 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.com?id=002' to
'href://www.somewhere.com/?var=X&new_id=002' 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.com?id=002' to
'href://www.somewhere.com/?var=X&new_id=002' 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

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

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 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.com?id=002' to
'href://www.somewhere.com/?var=X&new_id=002' 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

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

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 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="substring-before(.,'id=')"/>
<xsl:text>var=X&amp;new_id=</xsl:text>
<xsl:value-of select="substring-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.com?id=002' to
>'href://www.somewhere.com/?var=X&new_id=002' 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

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

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 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="substring-before(.,'id=')"/>
<xsl:text>var=X&amp;new_id=</xsl:text>
<xsl:value-of select="substring-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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Way | last post: by
1 post views Thread by mountain1228 | last post: by
reply views Thread by Christopher M. Lauer | last post: by
6 posts views Thread by Christopher | last post: by
reply views Thread by DAnne | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.