473,320 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XSLT: need help with xsl:for-each

Hello NG,

I try to apply the following template

<xsl:template match="objectgroup[@objid != '']">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
<xsl:variable name="object" select="."/>
<xsl:for-each select="//plugins/plugin">
<plugin pid="{./@pid}"
href="{//pluginobjectlist[@pid = ./@pid]/
objectgroup[@objid = $object/objid]/@href}"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>

to the follwoing xml-file

<symbol>
<objectgroup objid='id1'>
<!-- some elements here -->
</objectgroup>
<plugins>
<plugin pid="plug1"/>
<plugin pid="plug2"/>
<plugin pid="plug3"/>
</plugins>
<plugins>
<pluginobjectlist pid="plug1">
<objectgroup objid="obj1" href="url-p1-o1"/>
<!-- repeats for other objects -->
</pluginobjectlist>
<pluginobjectlist pid="plug2">
<objectgroup objid="obj1" href="url-p2-o1"/>
<!-- repeats for other objects -->
</pluginobjectlist>
<!-- repeats for remaining plugins -->
</plugins>
</symbol>

and I get the following result

<symbol>
<objectgroup objid='id1'>
<!-- some elements here -->
<plugin pid="plug1" href="url-p2-o1"/>
<plugin pid="plug2" href="url-p2-o1"/>
<plugin pid="plug3" href="url-p2-o1"/>
</objectgroup>
<!-- remaining templates remove plugin-elements -->
</symbol>

I see always the same url, so something in the xsl:for-each must
be wrong - but I can't see the problem.

Please give me a hint if you have an idea.

Thanx in advance,
Gerald
Jul 20 '05 #1
8 1398

href="{//pluginobjectlist[@pid = ./@pid]/
objectgroup[@objid = $object/objid]/@href}"/>
@pid (always) means the same as ./@pid so the first filter is always
true if there is a pid attribute. as it is[@pid =@pid] which is [@pid]

In your posted code objectgroup had an objid attribite not an objid
element child so $object/objid is the empty set.

David
Jul 20 '05 #2
David Carlisle wrote:
href="{//pluginobjectlist[@pid = ./@pid]/
objectgroup[@objid = $object/objid]/@href}"/>
@pid (always) means the same as ./@pid so the first filter is always
true if there is a pid attribute. as it is[@pid =@pid] which is [@pid]

I thought that the left part of the '='-part denotes the attribute
name to compare. How can I select the pluginobjectlist which pid-
attribute has the same value as the currend pid-attribut in the
xsl:for-each loop?
In your posted code objectgroup had an objid attribite not an objid
element child so $object/objid is the empty set.


Thank you for pointing this out, but fortunately it is a typo only.
The final is (except the open point from above):

href="{//pluginobjectlist[???]/
objectgroup[@objid = $object/@objid]/@href">/
Gerald
Jul 20 '05 #3
Gerald Aichholzer <ga**@sbox.tugraz.at> writes:
David Carlisle wrote:
href="{//pluginobjectlist[@pid = ./@pid]/
objectgroup[@objid = $object/objid]/@href}"/>
@pid (always) means the same as ./@pid so the first filter is always
true if there is a pid attribute. as it is[@pid =@pid] which is [@pid]

I thought that the left part of the '='-part denotes the attribute
name to compare.


Both sides of the = are evaluated the same way, as arbitrary XPath
expressions, then their values are compared for equality.
If you start a node-set valued XPath with something other than / or
.. then it's a relative XPath and taken relative to the current node
so @pid is _defined_ as meaning the same thing as ./@pid.

How can I select the pluginobjectlist which pid-
attribute has the same value as the currend pid-attribut in the
xsl:for-each loop? use a variable to hold the current node or equivalently the current()/functuion so something like
@pid = current()/@pid
or
@pid = $object/@pid
(I forget the exact structure of your input)
In your posted code objectgroup had an objid attribite not an objid
element child so $object/objid is the empty set.


Thank you for pointing this out, but fortunately it is a typo only.
The final is (except the open point from above):

href="{//pluginobjectlist[???]/
objectgroup[@objid = $object/@objid]/@href">/
Gerald

Jul 20 '05 #4
Hello David,

David Carlisle wrote:
Gerald Aichholzer <ga**@sbox.tugraz.at> writes:

David Carlisle wrote:
href="{//pluginobjectlist[@pid = ./@pid]/
objectgroup[@objid = $object/objid]/@href}"/>
[about @pid is the same as ./@pid]


How can I select the pluginobjectlist which pid-
attribute has the same value as the currend pid-attribut in the
xsl:for-each loop?


use a variable to hold the current node or equivalently the
current()/functuion


so something like
@pid = current()/@pid
or
@pid = $object/@pid
(I forget the exact structure of your input)


thank you, but I think I have given an incorrect example
by mistake (which doesn't represent the real problem).
My xml-file looks like this:

<symbol>
<objectgroup objid="abc">
<plugin pid="plugin1" href="..."/>
<plugin pid="plugin3" href="..."/>
</objectgroup>
<objectgroup objid="def">
<!-- ... -->
</objectgroup>
<!-- even more objectgroup elements -->
<plugins>
<plugin pid="plugin1"><desc>...</desc></plugin>
<plugin pid="plugin2"><desc>...</desc></plugin>
<plugin pid="plugin3"><desc>...</desc></plugin>
</plugins>
</symbol>

For each objectgroup/plugin element I'd like to access the
corresponding plugins/plugin element:

<xsl:template match="objectgroup">
<!-- do something -->
<xsl:for-each select="./plugin">
<xsl:value-of select="/symbol/plugins/plugin[???]/desc"/>
^^^
</xsl:for-each> |
<!-- do something --> |
</xsl:template> |
|
+---------------------------------------------------+
v

How can I select /symbol/plugins/plugin haven the same pid
as the current pid in the xsl:for-each loop?

thanks in advance,
Gerald
Jul 20 '05 #5
Hello NG,

I have a XML file looking like this:

<symbol>
<objectgroup objid="abc">
<plugin pid="plugin1" href="..."/>
<plugin pid="plugin3" href="..."/>
</objectgroup>
<objectgroup objid="def">
<!-- ... -->
</objectgroup>
<!-- even more objectgroup elements -->
<plugins>
<plugin pid="plugin1"><desc>...</desc></plugin>
<plugin pid="plugin2"><desc>...</desc></plugin>
<plugin pid="plugin3"><desc>...</desc></plugin>
</plugins>
</symbol>

For each objectgroup/plugin element I'd like to access the
corresponding plugins/plugin element using the following
template:

<xsl:template match="objectgroup">
<!-- do something -->
<xsl:for-each select="./plugin">
<xsl:value-of select="/symbol/plugins/plugin[???]/desc"/>
^^^
</xsl:for-each> |
<!-- do something --> |
</xsl:template> |
|
+---------------------------------------------------+
v

How can I select /symbol/plugins/plugin haven the same pid
as the current pid in the xsl:for-each loop?

thanks in advance,
Gerald
Jul 20 '05 #6

didn't we just do this?

<xsl:template match="objectgroup">
<!-- do something -->
<xsl:for-each select="plugin">
<xsl:value-of select="/symbol/plugins/plugin[@pid=current()/@pid]/desc"/>

</xsl:for-each>
<!-- do something -->
</xsl:template>
David
Jul 20 '05 #7
David Carlisle wrote:
didn't we just do this?

<xsl:template match="objectgroup">
<!-- do something -->
<xsl:for-each select="plugin">
<xsl:value-of select="/symbol/plugins/plugin[@pid=current()/@pid]/desc"/>

</xsl:for-each>
<!-- do something -->
</xsl:template>


Hello David,

I made it work just a few minutes ago - I think I have misinterpreted
your first answer or I haven't seen the wood from the trees.

thanx,
Gerald

Jul 20 '05 #8
Hello David,

David Carlisle wrote:

<xsl:template match="objectgroup">
<!-- do something -->
<xsl:for-each select="plugin">
<xsl:value-of select="/symbol/plugins/plugin[@pid=current()/@pid]/desc"/> ^^^^^^^^^^^^^^^^^
</xsl:for-each>
<!-- do something -->
</xsl:template>


I think I have some problems unterstanding XPath :/

In the above context (see ^^^) there are possibly three
different pid-attributes:

1) pid attribute of the objectgroup (xsl:template match)
which I have to access defining a xsl:variable outside
of the loop (is there also a way without a variable?)

2) pid attribute of xsl:for-each's current element
which I have to access with @pid (or ./@pid)

3) pid attribute of xsl:value-of's element which I have
to access using current()/@pid
Is my above understanding correct?

thanx for your help,
Gerald
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Jamie Burns | last post by:
Hello, I realise that I just dont get this, but I cannot see the need for auto_ptr. As far as I have read, it means that if you create an object using an auto_ptr, instead of a raw pointer, then...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
6
by: Pavel Vetesnik | last post by:
Hello, my question is probably quite stupid, but I really don't know how to solve it. I have code like this: =============================================== <button title="Osobní nastavení...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
0
by: Wilson Wu | last post by:
Hi, How can i create a xml and xsl for more than one worksheet. Thanks Wilson
3
by: Francesc | last post by:
Hi, I'm new at this newsgroup and I want do ask some questions and opinions about this subject. I'm developing an application focused in a very specific task: clean and labelling text documents...
11
by: sarathy | last post by:
Hi, I have been using C++ for a while. I am not entirely clear with the concepts of reference in C++. - Why was there a need for introducing a concept called "Reference" in C++ when everything...
0
by: [Cool staff!||Hi! I think this need for || Help me | last post by:
http://con-cern.org/files/2007/5/xenical-21024312.html cheap xenical http://con-cern.org/files/2007/5/auto-21024411.html auto loan refinance ...
4
by: parag_paul | last post by:
hi All I understand the need for long long , but what is the purpose of long as a data type separately. Just makes the language intimidating to start with, when you have to deal with so many data...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.