XPath problems...

C

cyphos

Hi,

I'm trying to display the data from my typed dataset on a page using
the Xml web control.

I have the following code:


Xm1.Document = new XmlDataDocument(ds);


Using the debugger, I found that the xml representation of my dataset
looks like the following:

[code:1:b261030e14]
<dsData>
<Entry>
<Title>Test</Title>
<Description>This is a test</Description>
</Entry>
</dsData>
[/code:1:b261030e14]

My xsl file looks like this

[code:1:b261030e14]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="dsData/Entry">
<div class="Entry">
<div class="EntryTitle">
<xsl:value-of select="Title"/>
</div>
<div class="EntryDescription">
<xsl:value-of select="Description"/>
</div>
</div>
</xsl:for-each>
</xsl:template>
</xsl"stylesheet>
[/code:1:b261030e14]

Using this stylesheet, nothing is displayed/transformed. I know that
it must be a stylesheet problem because if I don't set the
TransformSource property of the Xml control the raw xml of the
dataset (XmlDataDocument) is displayed.

I hope that someone understands this, as I'm lost.

Thanks,
Cyp.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
E

Elton Wang

If you use XSL file to transfer XML data to other file,
e.g. html, you should use class XslTransform as a bridge
to conduct output:

XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XslTransform xslTran = new XslTransform();
xslTran.Load(xslFile);
using(StreamWriter writer = new StreamWriter
(htmFile,false))
{
xslTran.Transform(xmlDoc, null, writer,null);
}

Hope it gives you some help.

Elton Wang
 
C

cyphos

Hi,

Thanks for your reply - I really appreciate it. However, I'm not sure
it's what I'm after, as I have a page with existing content on it.
I'm using the xml control to display specific data that changes. I'm
not sure how to use your code in my situation.

Regards,
Cyp.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
C

cyphos

Strange, but I got it work. I deleted the dataset, and created a new
one. However, this time I didn't create a typed dataset - and it
worked. I wonder how come it didn't work with a typed dataset?

Anyhow,
This leds to another XPath question, since the structure of my xml
changes.

I have the following xml:

<dsData>
<Entry>
<EntryID>10</EntryID>
<Title>Testing an entry</Title>
</Entry>
<Comment>
<CommentID>1</CommentID>
<EntryID>10</EntryID>
</Comment>
</dsData>


When I'm in a for-each loop that's selecting all Entry elements, I
want to display the total number of Comment elements that have the
current Entry's EntryID.

I have the following, but doesn't work:

[code:1:6efef00bb8]
<xsl:for-each select="dsData/Entry">
<!-- other content goes here -->
<value-of select="count(/Comment[EntryID =
{EntryID}])"/>
</xsl:for-each>
[/code:1:6efef00bb8]

Thanks!!!!
Cyp.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
E

Elton Wang

you might use
<xsl:number expr="count()" />
instead of
<value-of select="count()"/>

Elton Wang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top