Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : Build up xpath dynamically in xslt


tMan
6/4/2004 11:56:03 AM
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


Joe Gass
6/4/2004 2:13:08 PM
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

Joe Gass
6/9/2004 1:10:28 PM
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

[quoted text, click to view]
</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>
[quoted text, click to view]

AddThis Social Bookmark Button