Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default 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
  #2  
Old July 20th, 2005, 09:41 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: XSLT: need help with xsl:for-each


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
  #3  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default Re: XSLT: need help with xsl:for-each

David Carlisle wrote:[color=blue]
> 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]
>[/color]

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?
[color=blue]
> In your posted code objectgroup had an objid attribite not an objid
> element child so $object/objid is the empty set.[/color]

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
  #4  
Old July 20th, 2005, 09:41 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: XSLT: need help with xsl:for-each

Gerald Aichholzer <gary@sbox.tugraz.at> writes:
[color=blue]
> David Carlisle wrote:[color=green]
> > 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]
> >[/color]
>
> I thought that the left part of the '='-part denotes the attribute
> name to compare.[/color]

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.

[color=blue]
> How can I select the pluginobjectlist which pid-
> attribute has the same value as the currend pid-attribut in the
> xsl:for-each loop?[/color]
use a variable to hold the current node or equivalently the[color=blue]
> current()/functuion[/color]
so something like
@pid = current()/@pid
or
@pid = $object/@pid
(I forget the exact structure of your input)
[color=blue]
>[color=green]
> > In your posted code objectgroup had an objid attribite not an objid
> > element child so $object/objid is the empty set.[/color]
>
> 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[/color]
  #5  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default Re: XSLT: need help with xsl:for-each

Hello David,

David Carlisle wrote:[color=blue]
> Gerald Aichholzer <gary@sbox.tugraz.at> writes:
>
>[color=green]
>>David Carlisle wrote:
>>[color=darkred]
>>> href="{//pluginobjectlist[@pid = ./@pid]/
>>> objectgroup[@objid = $object/objid]/@href}"/>
>>>
>>>
>>> [about @pid is the same as ./@pid]
>>>[/color]
>>
>> How can I select the pluginobjectlist which pid-
>>attribute has the same value as the currend pid-attribut in the
>>xsl:for-each loop?[/color]
>
> use a variable to hold the current node or equivalently the
>[color=green]
>>current()/functuion[/color]
>
> so something like
> @pid = current()/@pid
> or
> @pid = $object/@pid
> (I forget the exact structure of your input)
>[/color]

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
  #6  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default XSLT: please help with XPath-expression

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
  #7  
Old July 20th, 2005, 09:41 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: XSLT: please help with XPath-expression


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
  #8  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default Re: XSLT: please help with XPath-expression

David Carlisle wrote:[color=blue]
> 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>
>[/color]

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

  #9  
Old July 20th, 2005, 09:41 AM
Gerald Aichholzer
Guest
 
Posts: n/a
Default understanding XPatch-expressions (was: XSLT: please help with XPath-expression)

Hello David,

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

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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles