BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

XSL for-each / select problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML
View previous topic :: View next topic  
Author Message
Andi
Guest





PostPosted: Sun May 08, 2005 3:35 pm    Post subject: XSL for-each / select problem Reply with quote



Hello,

maybe this is not quite a Delphi problem but I encountered it while using
TXSLPageProducer (and maybe it is related to this component):

I have this XML document:

<project>
<items>
<entity class="product" />
<entity class="other" />
</items>
</project>

and this XSL stylesheet (extract) for transformation:

<xsl:template match="items">
<xsl:for-each select="entity[@class='product']">
...
</xsl:for-each>
</xsl:template>

which should handle any "entity" node with class="product". But here, it
doesn't work, it gives me an empty node set.

What does work is this:
...
<entity class-id="1" />
...
and
<xsl:for-each select="entity[@class-id=1]">

i.e. renaming class to class-id, using a number rather than a text and
omitting the '...' around the 1. Why is this? Is my above XSL script wrong
(I found this formulation in several XSL guides)?

Thanks
Andi


Back to top
Marc Scheuner
Guest





PostPosted: Mon May 09, 2005 5:39 am    Post subject: Re: XSL for-each / select problem Reply with quote



Quote:
project
items
entity class="product" /
entity class="other" /
/items
/project

and this XSL stylesheet (extract) for transformation:

xsl:template match="items"
xsl:for-each select="entity[@class='product']"
...
/xsl:for-each
/xsl:template

which should handle any "entity" node with class="product". But here, it
doesn't work, it gives me an empty node set.

No, you're XSL is wrong - what you are selecting are TOP-LEVEL nodes
of type "entity".

If you REALLY want ANY nodes of type entity, you need to use this
syntax:

<xsl:for-each select="//entity[@class='product']">

Or if you need to select all entity object below the project/items
node, use this:

<xsl:for-each select="project/items//entity[@class='product']">

Just specifying "entity" without anything else will go look in the
ROOT of your XML document!

Marc

================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch

Back to top
Jeff Rafter
Guest





PostPosted: Tue May 10, 2005 1:21 pm    Post subject: Re: XSL for-each / select problem Reply with quote



It must be related to the component because your XSLT is 100% okay. When
you do a for-each without the select statement is bound to the current
context. So:

select="entity[...]"

Means select the entity in the current context (which is items). You can
explicitly root it by adding a single "/", or you can search all nodes
using "//". You should use "//" very sparingly though as it is death for
the performance of your stylesheet.

The full XSLT I used was:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
<xsl:template match="items">
<xsl:for-each select="entity[@class='product']">
<xsl:value-of select="@class"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

<?xml version="1.0"?>
<project>
<items>
<entity class="product" />
<entity class="other" />
</items>
</project>

The output was:

product

Perhaps there is a version issue-- do you have MSXML3 or MSXML4
installed? Are you using namespaces in your document? If you would like
there is a lot of code for transforming the document without the
component (but using msxml). Search Google Groups for

IXSLProcessor Delphi

Cheers,
Jeff Rafter
Back to top
Andi
Guest





PostPosted: Wed May 11, 2005 2:07 pm    Post subject: Re: XSL for-each / select problem Reply with quote

Now it works, but dont ask me why! I didn't change anything, and suddenly
everything is ok!
Thanks anyway.


"Andi" <andi (AT) hunter (DOT) numerikon.de> schrieb im Newsbeitrag
news:427e31d2$1 (AT) newsgroups (DOT) borland.com...
Quote:
Hello,

maybe this is not quite a Delphi problem but I encountered it while using
TXSLPageProducer (and maybe it is related to this component):

I have this XML document:

project
items
entity class="product" /
entity class="other" /
/items
/project

and this XSL stylesheet (extract) for transformation:

xsl:template match="items"
xsl:for-each select="entity[@class='product']"
...
/xsl:for-each
/xsl:template

which should handle any "entity" node with class="product". But here, it
doesn't work, it gives me an empty node set.

What does work is this:
...
entity class-id="1" /
...
and
xsl:for-each select="entity[@class-id=1]"

i.e. renaming class to class-id, using a number rather than a text and
omitting the '...' around the 1. Why is this? Is my above XSL script wrong
(I found this formulation in several XSL guides)?

Thanks
Andi





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.