364,085 Members | 5253 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Build up xpath dynamically in xslt

Joe Gass
P: n/a
Joe Gass
After a bit of research I think what I'm trying to do with xslt can't be
done, but someone may have some pointers.

I have 2 sections in my xml - 1 with properties the 2nd with image path data
each property can have more than 1 set of image path nodes

What I'm trying to do is transform the property data into the format I
require at the same time finding any associatted image paths

Here's my xml

<web_transfer>
<property>
<uniquereferenceid>1a</uniquereferenceid>
....
</property>
<property>
<uniquereferenceid>2a</uniquereferenceid>
....
</property>

<images>
<uniquereferenceid>1a</uniquereferenceid>
<imageurl>http://www.com/testimage1.jpg</imageurl>
</images>
<images>
<id>636</id>
<uniquereferenceid>2a</uniquereferenceid>
<imageurl>http://www.com/testimage2.jpg</imageurl>
</images>
<web_transfer>

An xpath like
/web_transfer/images[uniquereferenceid='1a'][position()=1]/imageurl
works fine, when used outside my xslt.

In my xslt

<xsl:template match="/">
<xsl:for-each select="web_transfer/property">
<xsl:variable name="myString1">
<xsl:value-of
select="/web_transfer/images[uniquereferenceid=uniquereferenceid][position()
=1]/imageurl"/>
</xsl:variable>

<image1>
<xsl:value-of select="$myString1"/>
</image1>

</xsl:for-each>
</xsl:template>

Hoping that the bit [uniquereferenceid=uniquereferenceid] would get filled
in to be [uniquereferenceid=1a] etc
It isn't and I don't get any data back

Any suggestions appreciatted
Thanks


Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


tMan
P: n/a
tMan
i don't think you can do that in XPath 1.0. you might have to look for some extensions
http://www.dpawson.co.uk/xsl/sect2/nono.html#d1761e3

http://www.exslt.org/dyn/functions/evaluate/index.htm

----- Joe Gass wrote: ----

After a bit of research I think what I'm trying to do with xslt can't b
done, but someone may have some pointers

I have 2 sections in my xml - 1 with properties the 2nd with image path dat
each property can have more than 1 set of image path node

What I'm trying to do is transform the property data into the format
require at the same time finding any associatted image path

Here's my xm

<web_transfer><property><uniquereferenceid>1a</uniquereferenceid
...
</property><property><uniquereferenceid>2a</uniquereferenceid
...
</property><images><uniquereferenceid>1a</uniquereferenceid><imageurl>http://www.com/testimage1.jpg</imageurl></images><images><id>636</id><uniquereferenceid>2a</uniquereferenceid><imageurl>http://www.com/testimage2.jpg</imageurl></images><web_transfer

An xpath lik
/web_transfer/images[uniquereferenceid='1a'][position()=1]/imageur
works fine, when used outside my xslt

In my xsl

<xsl:template match="/"><xsl:for-each select="web_transfer/property"><xsl:variable name="myString1"><xsl:value-o
select="/web_transfer/images[uniquereferenceid=uniquereferenceid][position(
=1]/imageurl"/></xsl:variable><image1><xsl:value-of select="$myString1"/></image1></xsl:for-each></xsl:template

Hoping that the bit [uniquereferenceid=uniquereferenceid] would get fille
in to be [uniquereferenceid=1a] et
It isn't and I don't get any data bac

Any suggestions appreciatte
Thank



Nov 12 '05 #2

tMan
P: n/a
tMan
i don't think you can do that in XPath 1.0. you might have to look for some extensions
http://www.dpawson.co.uk/xsl/sect2/nono.html#d1761e3

http://www.exslt.org/dyn/functions/evaluate/index.htm

----- Joe Gass wrote: ----

After a bit of research I think what I'm trying to do with xslt can't b
done, but someone may have some pointers

I have 2 sections in my xml - 1 with properties the 2nd with image path dat
each property can have more than 1 set of image path node

What I'm trying to do is transform the property data into the format
require at the same time finding any associatted image path

Here's my xm

<web_transfer><property><uniquereferenceid>1a</uniquereferenceid
...
</property><property><uniquereferenceid>2a</uniquereferenceid
...
</property><images><uniquereferenceid>1a</uniquereferenceid><imageurl>http://www.com/testimage1.jpg</imageurl></images><images><id>636</id><uniquereferenceid>2a</uniquereferenceid><imageurl>http://www.com/testimage2.jpg</imageurl></images><web_transfer

An xpath lik
/web_transfer/images[uniquereferenceid='1a'][position()=1]/imageur
works fine, when used outside my xslt

In my xsl

<xsl:template match="/"><xsl:for-each select="web_transfer/property"><xsl:variable name="myString1"><xsl:value-o
select="/web_transfer/images[uniquereferenceid=uniquereferenceid][position(
=1]/imageurl"/></xsl:variable><image1><xsl:value-of select="$myString1"/></image1></xsl:for-each></xsl:template

Hoping that the bit [uniquereferenceid=uniquereferenceid] would get fille
in to be [uniquereferenceid=1a] et
It isn't and I don't get any data bac

Any suggestions appreciatte
Thank



Nov 12 '05 #3

Joe Gass
P: n/a
Joe Gass
Thanks Tman, you're right it can't be done as I was trying to do it.

I found the solution in microsoft.public.xsl
The answer was to use <xsl:key>

Cheers

"tMan" <anonymous@discussions.microsoft.com> wrote in message
news:9B8A7EBD-CAB9-4BE5-976C-85778757CD43@microsoft.com...[color=blue]
> i don't think you can do that in XPath 1.0. you might have to look for[/color]
some extensions.[color=blue]
> http://www.dpawson.co.uk/xsl/sect2/nono.html#d1761e34
>
> http://www.exslt.org/dyn/functions/evaluate/index.html
>
> ----- Joe Gass wrote: -----
>
> After a bit of research I think what I'm trying to do with xslt can't[/color]
be[color=blue]
> done, but someone may have some pointers.
>
> I have 2 sections in my xml - 1 with properties the 2nd with image[/color]
path data[color=blue]
> each property can have more than 1 set of image path nodes
>
> What I'm trying to do is transform the property data into the format[/color]
I[color=blue]
> require at the same time finding any associatted image paths
>
> Here's my xml
>
> <web_transfer><property><uniquereferenceid>1a</uniquereferenceid>
> ....
> </property><property><uniquereferenceid>2a</uniquereferenceid>
> ....
>[/color]
</property><images><uniquereferenceid>1a</uniquereferenceid><imageurl>http:/
/www.com/testimage1.jpg</imageurl></images><images><id>636</id><uniquerefere
nceid>2a</uniquereferenceid><imageurl>http://www.com/testimage2.jpg</imageur
l></images><web_transfer>[color=blue]
>
> An xpath like
> /web_transfer/images[uniquereferenceid='1a'][position()=1]/imageurl
> works fine, when used outside my xslt.
>
> In my xslt
>
> <xsl:template match="/"><xsl:for-each[/color]
select="web_transfer/property"><xsl:variable name="myString1"><xsl:value-of[color=blue]
>[/color]
select="/web_transfer/images[uniquereferenceid=uniquereferenceid][position()[color=blue]
> =1]/imageurl"/></xsl:variable><image1><xsl:value-of[/color]
select="$myString1"/></image1></xsl:for-each></xsl:template>[color=blue]
>
> Hoping that the bit [uniquereferenceid=uniquereferenceid] would get[/color]
filled[color=blue]
> in to be [uniquereferenceid=1a] etc
> It isn't and I don't get any data back
>
> Any suggestions appreciatted
> Thanks
>
>
>[/color]


Nov 12 '05 #4

Joe Gass
P: n/a
Joe Gass
Thanks Tman, you're right it can't be done as I was trying to do it.

I found the solution in microsoft.public.xsl
The answer was to use <xsl:key>

Cheers

"tMan" <anonymous@discussions.microsoft.com> wrote in message
news:9B8A7EBD-CAB9-4BE5-976C-85778757CD43@microsoft.com...[color=blue]
> i don't think you can do that in XPath 1.0. you might have to look for[/color]
some extensions.[color=blue]
> http://www.dpawson.co.uk/xsl/sect2/nono.html#d1761e34
>
> http://www.exslt.org/dyn/functions/evaluate/index.html
>
> ----- Joe Gass wrote: -----
>
> After a bit of research I think what I'm trying to do with xslt can't[/color]
be[color=blue]
> done, but someone may have some pointers.
>
> I have 2 sections in my xml - 1 with properties the 2nd with image[/color]
path data[color=blue]
> each property can have more than 1 set of image path nodes
>
> What I'm trying to do is transform the property data into the format[/color]
I[color=blue]
> require at the same time finding any associatted image paths
>
> Here's my xml
>
> <web_transfer><property><uniquereferenceid>1a</uniquereferenceid>
> ....
> </property><property><uniquereferenceid>2a</uniquereferenceid>
> ....
>[/color]
</property><images><uniquereferenceid>1a</uniquereferenceid><imageurl>http:/
/www.com/testimage1.jpg</imageurl></images><images><id>636</id><uniquerefere
nceid>2a</uniquereferenceid><imageurl>http://www.com/testimage2.jpg</imageur
l></images><web_transfer>[color=blue]
>
> An xpath like
> /web_transfer/images[uniquereferenceid='1a'][position()=1]/imageurl
> works fine, when used outside my xslt.
>
> In my xslt
>
> <xsl:template match="/"><xsl:for-each[/color]
select="web_transfer/property"><xsl:variable name="myString1"><xsl:value-of[color=blue]
>[/color]
select="/web_transfer/images[uniquereferenceid=uniquereferenceid][position()[color=blue]
> =1]/imageurl"/></xsl:variable><image1><xsl:value-of[/color]
select="$myString1"/></image1></xsl:for-each></xsl:template>[color=blue]
>
> Hoping that the bit [uniquereferenceid=uniquereferenceid] would get[/color]
filled[color=blue]
> in to be [uniquereferenceid=1a] etc
> It isn't and I don't get any data back
>
> Any suggestions appreciatted
> Thanks
>
>
>[/color]


Nov 12 '05 #5

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework