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

dotnet xml : XSL not working as expected....


Marc Scheuner [MVP ADSI]
6/18/2004 8:21:53 AM
Folks,

I'm trying to get something done in XSL and either I'm just missing
some silly thing, or it's not possible to do it.... which is it???

What I'm trying to do is have a XML document that (to some degree)
describes a report - basically, it's a collection of labels and XPath
references of where in the XML document to find the values for those
labels. Seems pretty simple and straightforward, and looks something
like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<reportstruct>
<firstpage>
<items>
<item>
<label>Label 1</label>
<ref>/dbdata/basic/item1</ref>
</item>
<item>
<label>Label 2</label>

<ref>//dbdata/basic/item2</ref>
</item>
</items>
</firstpage>
</reportstruct>
<dbdata>
<basic>
<item1>10299</item1>
<item2>1.850.897</item2>
</basic>
</dbdata>
</root>

So what I'd like to see in my final HTML is a table with all the
labels as defined in the "root/reportstruct/items" collection, and
their associated value as specified in the "ref" element for each
<item>.

My XSL for that part looks something like this:

<table width="100%">
<xsl:for-each select="root/reportstruct/firstpage/items/item">
<tr>
<td style="font-weight: bold" width="50%">
<xsl:value-of select="label" />
</td>
<td>
<xsl:variable name="DataRef"
select="ref" />
<xsl:value-of select="{$DataRef}" />
</td>
</tr>
</xsl:for-each>
</table>

So give me all the <item> nodes, display the "label" element in the
first data cell, grab the reference (XPath expression) for the value,
and display that one in the second data cell.

Unfortunately, I can't seem to get it to work - trying to
XSL-transform this with MSXSL keeps telling me that the {$DataRef} is
not a valid XPath expression, that it contains "an illegal token" (but
fails to say WHAT that token is!).

Any ideas?? I must be really either not seeing something very basic,
or something is screwy.....

Any hints are most welcome!!

Marc
================================================================
Marc Scheuner May The Source Be With You!
Martin Honnen
6/18/2004 1:09:42 PM


[quoted text, click to view]


[quoted text, click to view]

{$DataRef} is a so called attribute value template you could use as the
attribute value of a literal result element but not as the value of the
select attribute.

There is no dynamic evaluation of strings as XPath expressions in XPath
1.0 which both MSXML and .NET implement currently so your attempt to
have an XPath expression as the text content of an element and evaluate
that in your XSLT stylesheet will not work. If you want to reference
other elements have a look at ID/IDREF attributes and then you can use
the id function in XPath.
--

Martin Honnen
http://JavaScript.FAQTs.com/
AddThis Social Bookmark Button