Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XML and XSLT question. Please help me out... (http://www.velocityreviews.com/forums/t170085-xml-and-xslt-question-please-help-me-out.html)

dennis 10-27-2005 02:10 AM

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


hilz 10-27-2005 04:12 AM

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


> 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?

dennis 10-27-2005 09:21 AM

Re: XML and XSLT question. Please help me out...
 
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


hilz 10-27-2005 08:47 PM

Re: XML and XSLT question. Please help me out...
 
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

Peter Flynn 10-27-2005 10:08 PM

Re: XML and XSLT question. Please help me out...
 
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/


dennis 10-28-2005 03:45 PM

Re: XML and XSLT question. Please help me out...
 
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/




All times are GMT. The time now is 06:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.